Persisting a custom UUID class as a VARCHAR

The intended way is to register a custom org.hibernate.type.descriptor.java.JavaTypeDescriptor with the JavaTypeDescriptorRegistry. Then the AttributeConverter would simply work.

The JavaTypeDescriptorRegistry can be accessed from the org.hibernate.type.spi.TypeConfiguration which in turn can be accessed via:

  1. org.hibernate.boot.internal.BootstrapContextImpl#getTypeConfiguration
  2. SessionFactoryImplementor#getMetamodel -> MetamodelImplementor#getTypeConfiguration
  3. org.hibernate.boot.spi.MetadataImplementor#getTypeConfiguration

depending on where you are in the SessionFactory lifecycle.

The easiest way to register JavaTypeDescriptor (or other type system extensions) is a custom org.hibernate.boot.model.TypeContributor implementation which Hibernate will discover using Java’s standard ServiceLoader mechanism.