How do I execute a method just before saving a model?
Like for example hashing passwords in a User Model.
@Before annotation does not seem to exist for models.
I am using PlayFramework 1.2.x
PS : I plan on using it with the CRUD Module.
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.
Check out the collection of
Pre*annotations in JPA. For examplePrePersistandPreUpdate.In your model, just stick the annotation you need onto the method that you want to invoke.
Another option might be to override the
save()method for the particular model, but I wouldn’t do that unless it’s completely necessary. I would stick to the JPA APIs if they offer a solution, but that is just my opinion.