I have a use case I'm having trouble finding documentation for. I would like to generate a natural id when an object is saved to the database for the first time. The object has three ids, a sequential integer surrogate id generated by the database that is used in joins (the primary key), a uuid intended for collating data between separate installations of the system and a short, randomly generated hexidecimal string that is exposed to users.
It would be convenient to be able to do something like the following in the case of the uuid:
Code:
<natural-id>
<property name="uuid" column="uuid">
<generator class="guid"/>
</property>
</natural-id>
I understand the equivalent can be achieved through a trigger or by setting the relevant setter on the object before it is persisted. I've also come accross a reference in one of the FAQs to writing a CompositeUserType and then defining a custom IdentifierGenerator (I assume the custom IdentifierGenerator isn't relevant here).
There is an open issue for a related feature concerning allowing a generator in a composite id element.
http://opensource.atlassian.com/project ... e/HHH-2060
What is a good practice in the above use case? Am I missing something in trying to do things this way?
Thanks in advance for any help.
Eric
Hibernate version: Hibernate 3.2