Make UUID generation the default (AUTO) for UUID type

Description

Report from the discussion started here
http://lists.jboss.org/pipermail/hibernate-dev/2015-January/012082.html

The idea was to support UUID generation when @GeneratedValue(AUTO) is set on a UUID property. I proposed String too but Steve is more skeptical.

Another aspect is to bind the UUID property to the native UUID type in the database. This is related to and

A final and related aspect is to make the AUTO/IDENTITY/SEQUNCE generation mapping to be customizable based on data like the (OGM) dialect and the type. For example OGM would plug an implementation that uses MongoDB ObjectId generation for IDENTITY.

Activity

Show:

AL October 27, 2016 at 2:49 PM

I believe I found the solution. I needed to mark my UUID types with type "uuid-binary". Verified that this generates they type as bytea in Postgres and that i can read records from my existing database.

@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Type(type = "uuid-binary")
private UUID id;

AL October 26, 2016 at 10:05 PM

For those of us upgrading from Hibernate 4 to 5, how are we supposed to keep the Hibernate 4 behavior as right now the upgrade is not backwards compatible with the existing schema.

See: http://stackoverflow.com/questions/40272819/hibernate-5-breaks-legacy-handling-of-java-uuid-in-postgresql

Thank you.

Fixed

Details

Assignee

Reporter

Time tracking

0.63h logged

Components

Fix versions

Priority

Created January 20, 2015 at 3:32 PM
Updated October 27, 2016 at 2:49 PM
Resolved March 21, 2015 at 7:45 PM