Type annotation of Hibernate is not working

4.6k Views Asked by At

I want to convert UUID value from bytes to string by using @Type annotation as: @Type(type="uuid-char") but I am getting the error: The attribute type is undefined for the annotation type Type.

Import: import org.hibernate.annotations.Type; Code:

    @Id
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator")
    @Column(name = "id", columnDefinition = "VARCHAR(40)")
    @Type(type="uuid-char")
    @JsonIgnore
    private UUID id;

I also searched it here https://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#d0e2794 but it had the same syntax I was using. What am I missing?

2

There are 2 best solutions below

1
mask3007 On

Try use @JdbcTypeCode(SqlTypes.VARCHAR) instead.

After updating to Spring Boot 3.0.0 we had the same problem. Using @JdbcTypeCode(SqlTypes.VARCHAR) instead. I tried it out with PSQL.

0
Nishant Bharat On

Tried a workaround to save the UUID string to the database. I changed the data type of the id field from UUID to String and it worked fine.

Updated entity class definition:

@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator")
@Column(name = "id", columnDefinition = "VARCHAR(40)")
@JsonIgnore
private String id;