Create value for property in hibernation
1 answer
The easiest way is to simply treat this alternate key like any other "normal" property in your pojo. Whenever you instantiate a new object, you just do something like
myinstance.setAlternateKey(UUID.randomUUID().toString());
If you want hibernate to automatically create a new UUID when you save a new object to the database, you could do so using hibernate interceptors and event listeners , especially PreInsertEventListener.
+1
source to share