0

I have the following Entity

@Entity
@Table(name = "utente")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "username")
public class Utente {


//Primary key
@Id
@Column(name = "username", nullable=false, unique=true)
private String username;

//Attributes
@Enumerated(EnumType.STRING)
@Column(name = "ruolo", columnDefinition = "ENUM('admin', 'supervisore', 'cameriere','cuoco')", nullable=false)
private Ruolo ruolo;

//getters and setters...

}

My class Ruolo is defined like this:

public enum Ruolo {
    @JsonProperty("admin")
    admin,
    @JsonProperty("supervisore")
    supervisore,
    @JsonProperty("cuoco")
    cuoco,
    @JsonProperty("cameriere")
    cameriere
}

And it refers to this Enumeration in my Postgres DB

CREATE TYPE public.ruolo AS ENUM
    ('admin', 'supervisore', 'cameriere', 'cuoco');

ALTER TYPE public.ruolo
    OWNER TO postgres;

When I use the CrudRepository save method (from JPA), i get this PostgreSQLException:

2023-03-04T17:29:42.614+01:00  WARN 15656 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 42804
2023-03-04T17:29:42.614+01:00 ERROR 15656 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : ERROR: column "ruolo" Þ of type ruolo but the expression Þ of type character varying
  Suggestion: You must rewrite or convert the type of the expression.

Any idea? I get the object Utente from Json

0 Answers0