moyowi
moyowi

Reputation: 23

Hibernate generate a Long id value instead of UUID

I am using quarkus (0.17). I do an entity with panache to connect at posgresql. My table has an uuid key and is defined as it :

 CREATE TABLE public.instruments
(
    id uuid,
    name character varying(50)
)

I setted the hibernate dialect in application.properties as it :

quarkus.hibernate-orm.dialect =  org.hibernate.dialect.PostgreSQL95Dialect

My entity is defined as it :

@Entity
@Table(name="instruments")
public class Instrument extends PanacheEntity{

    @Id
    @GeneratedValue( generator = "UUID" )
    @GenericGenerator(
        name = "UUID",
        strategy = "org.hibernate.id.UUIDGenerator",
        parameters = {
            @Parameter(
                name = "uuid_gen_strategy_class",
                value = "org.hibernate.id.uuid.CustomVersionOneStrategy"
            )
        }
    )
    @Type(type="pg-uuid")   
    public UUID id;
    public String name; 

}

At runtime, when I try to persist my entity, I have a java.lang.IllegalArgumentException: Can not set java.util.UUID field xxxx.entity.Instrument.id to java.lang.Long.

Upvotes: 2

Views: 2575

Answers (1)

Guillaume Smet
Guillaume Smet

Reputation: 10539

PanacheEntity adds its own id:

    @Id
    @GeneratedValue
    public Long id;

So what you need is to extend PanacheEntityBase which is a bit more low level and does not come with an id.

Upvotes: 7

Related Questions