Dialect specific UUID handling

Description

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.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 @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

1 2 3 4 5 6 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

1 @Type( "pg-uuid" )

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".

Environment

None

Status

Assignee

Unassigned

Reporter

Caleb Cushing

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

4.3.7

Priority

Major
Configure