I want to generate a unique guid/uuid value for a property which is not a primary key in hibernate. In other words, I want to generate values for an alternate primary key.
How can I do this using Hibernate?
I want to generate a unique guid/uuid value for a property which is not a primary key in hibernate. In other words, I want to generate values for an alternate primary key.
How can I do this using Hibernate?
The easiest way might be to just treat this alternate key like every other "normal" property of your pojo. Whenever you create a new instance of an object you just something like
myinstance.setAlternateKey(UUID.randomUUID().toString());
If your want hibernate to automatically create a new UUID when saving a new object to the database, then you could do this by using hibernate's interceptors and event listeners, especially the PreInsertEventListener.