Hi,
I've got an entity class which contains a java.util.UUID. Since my database is MySQL and it does not support the UUID type I have explicitly declared the column definition to be a
varchar(36). My code looks like the following:
Code:
@Entity
@Table(name = "my_table")
public class MyClass
{
private UUID uuid;
@Column(columnDefinition = "varchar(36)", updatable = false, unique = true)
public UUID getUuid()
{
return uuid;
}
public void setUuid(UUID uuid)
{
this.uuid = uuid;
}
}
Unfortunately I am having a problem with retrieving objects from the database as it seems Hibernate doesn't know how to convert a UUID to String or vice versa. Now I realize I could make the internal field a String and annotate that instead of the getter but that creates a problem when I need subclasses to be able to override the annotations and still get all the base class annotations.
So is there a way to tell Hibernate to use some other serializer or can create I create a custom one? or is there a better way to store UUID in MySQL? Any help is greatly appreciated.