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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
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.