Reputation: 3895
I'm just curious if there is a way to bypass the beforeUpdate()
and similar methods of a certain domain class.
I need it for restoring the original password of a user. The beforeUpdate
proceeds the password hashing algorithm which I wouldn't like to call twice.
The only solution I could come up with is to use direct connection to the database and therefore bypass the Hibernate
. This I don't like much cause of DB vendor lock-in etc.
Thanks for any advice.
Upvotes: 0
Views: 295
Reputation: 12334
You can use HQL:
User.executeUpdate("update User u set u.password = :password where u.id = :userId",
[password: oldHashedPassword, userId: userId])
This still uses Hibernate and its abstraction from your datasource vendor.
Upvotes: 1
Reputation: 5540
Why don't you put a ishashed property on the domain....
You put it to false when you set the new password
In the beforeUpdate you test ishashed
if false you hash the password and set ishashed to true
Upvotes: 1