Persisting a custom UUID class as a VARCHAR

Instead of using a UUIDConverter, you could create a Hibernate custom Type instead and register that with Hibernate.

Check out this article for an example. Basically, you will have to provide the following @TypeDef after you created your custom UUIDType:

@TypeDef(
	name = "custom-uuid", 
	typeClass = CustomUUIDType.class, 
	defaultForType = com.leo.commons.utils.UUID.class
)

And then you don’t really need to do anything in the UUID entity property mapping.

1 Like