Hi, I am using Spring + Hibernate to create and store a record in a MySQL database.
Just before persisting a record I want my system to generate a random-string which will be stored in a field in the entity that is being stored. This random-string of characters will be used later as an access-key to retreive the record and confirm the user's input.
I thought of using a method in my entity class annotated with @PrePersist to realize this behaviour. Is this the proper place to put such a method?
This question occured to me as I would not know how to check the database table for the uniqueness of the random-string as I cannot think of a way to reference the spring's HibernateTemplate instance to do a query from within the entity class.
Any suggestion is much appreciated.