So i have this ENUM in my PostgreSQL:
CREATE TYPE process_status AS ENUM('CREATED','ONGOING','DONE');
ALTER TABLE process ADD status process_status NOT NULL DEFAULT 'CREATED';
In my code:
@Getter
public enum Status {
CREATED("Created"),
ONGOING("Ongoing"),
DONE("Done");
private final String status;
Status(String status) {
this.status = status;
}
}
In my Process class i use the enum:
public class Process extends RepresentationModel<Process> implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;
@Enumerated(EnumType.STRING)
private Status status = Status.CREATED;
}
In my repository:
public interface ProcessRepository extends JpaRepository<Process, UUID> {
List<Process> findByIdNotAndStatusNot(UUID id, Status status);
}
In my service i call the Repository
processList = processRepository.findByIdNotAndStatusNot(id, Status.DONE);
And i get this error:
ERROR: operator does not exist: process_status <> character varying
Does anyone have an idea of what am i doing wrong?
2
Answers
My solution was to add the @ColumnTransformer annotation to cast the types:
It’s because there is no automatic cast between varchar and your type, you can check PostgreSQLEnumType from hypersistence-utils or implement your own. Otherwise you can also create an automatic cast in the DB side https://www.postgresql.org/docs/current/sql-createcast.html.