0

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.

David Mulder
  • 26,123
  • 9
  • 51
  • 114
kuceram
  • 3,795
  • 9
  • 34
  • 54

2 Answers2

1

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

Fabiano Taioli
  • 5,270
  • 1
  • 35
  • 49
  • I was thinking about this solution before but found some problems. But actually there are no - quite straight forward solution. Thank you! – kuceram Mar 21 '13 at 09:08
1

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.

codelark
  • 12,254
  • 1
  • 45
  • 49