kuceram
kuceram

Reputation: 3895

Grails Bypass beforeUpdate Method of a Domain class

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

Answers (2)

codelark
codelark

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

Fabiano Taioli
Fabiano Taioli

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

Related Questions