In my application I have a User domain object that has a handful of fields in it including a password field. The password field is an encrypted String using JASYPT. For development purposes I am creating a new user on startup that is hard coded. It looks like this:
User user = new User(
userId:"user1", userFname:"Joe",
userLname:"Blow", userMinit:"A",
userEmail:"joe@blow.com", userPword:"password").save()
When the save() is called I believe that in the background the hibernate saveOrUpdate() is being called. It is comparing the new domain objects field values against already existing domain object field values to decide if the record should be inserted into the db or if it should just update an already existing record.
Since the password field is always going to be a new value because of the JASYPT encryption it is inserting a new record every time.
INSERT INTO USER VALUES(1,'joe@blow.com',
'Joe','user1','Blow','A','','','',
'gIkUvM9b6d5vrEhkKzqKz0U7uxqRpZFhiQrrBTDbKX0=')
INSERT INTO USER VALUES(2,'joe@blow.com',
'Joe','user1','Blow','A','','','',
'yap0S0mCb2CpGngcANpSWoLqlL6SozLYK4WbKYHSVEw=')
Here is the Domain class:
@Table(name="user")
class User {
String userId
String userFname
String userLname
String userMinit
String userEmail
String userPword
String userMisc1 = ""
String userMisc2 = ""
String userMisc3 = ""
public User(){};
static mapping = {
version false
columns {
userId column:'user_id'
userFname column:'user_fname'
userLname column:'user_lname'
userMinit column:'user_minit'
userEmail column:'user_email'
userPword column:'user_pword'
userMisc1 column:'user_misc1'
userMisc2 column:'user_misc2'
userMisc3 column:'user_misc3'
}
userPword type: GormEncryptedStringType
}
static constraints = {}
}
Is there a way to tell GORM to ignore the password field when saving the domain object so I don't end up with the same user over and over in the DB?
Thanks for any help.