|
So, I think I've gone mad, I've tried every combination I can think of to get Hibernate to use a Native UUID object and a Postgres uuid type, whilst having my tests use H2, every attempt has resulted exceptions.
my latest is my own custom type, for which I can't figure out how to correctly detect the Dialect.
public static final String UUID = "uuid-custom";
private static final Logger log = LoggerFactory.getLogger( UUIDCustomType.class );
private static final long serialVersionUID = 902830399800029445L;
private static SqlTypeDescriptor sqlTypeDescriptorFactory() {
Dialect dialect = Dialect.getDialect( );
SqlTypeDescriptor descriptor
= ( dialect instanceof PostgreSQL9Dialect )
? PostgresUUIDType.PostgresUUIDSqlTypeDescriptor.INSTANCE
: VarcharTypeDescriptor.INSTANCE;
return descriptor;
}
public UUIDCustomType() {
super(sqlTypeDescriptorFactory(), UUIDTypeDescriptor.INSTANCE);
}
@Override
public String getName() {
return UUID;
}
@Id
@NotNull
@Override
@Generated( GenerationTime.ALWAYS )
@GeneratedValue( generator = "entityIdGenerator" )
@GenericGenerator( name = "entityIdGenerator", strategy = "uuid2" )
@Column( columnDefinition = "uuid", updatable = false )
public UUID getId() {
return id;
}
@TypeDef(
name = UUIDCustomType.UUID,
defaultForType = UUID.class,
typeClass = UUIDCustomType.class
)
here's the package-info.java
package com.xenoterracide.rpf.model;
import com.xenoterracide.rpf.infrastructure.db.UUIDCustomType;
import org.hibernate.annotations.TypeDef;
import java.util.UUID;
I've also tried
which works great for postgres, but I can't get it to downgrade for H2.
I am at the point of guessing this can't be done currently, though it seems unreasonable because both Postgres and H2 support type "uuid".
|