-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Advice needed on how to NOT update one field of an entity
PostPosted: Tue Feb 17, 2009 6:55 pm 
Beginner
Beginner

Joined: Sat Feb 07, 2009 4:08 pm
Posts: 22
Location: New York City
I need advice on this simple strategy question: I have a typical User entity which among other fields, has a <String> password. When I update the user object I do not want to update the password because it is encrypted in the database and the user object that I am updating, that has been passed in from the UI, contains the unencrypted password that the user has entered (which i use to validate the user performing the update.)

What is the best way to make the password only get inserted when creating a new user, but never updated. Should PASSWORD be an embedded component? Does it have to be a ONE-TO-ONE association with a specific cascade type set? Should PASSWORD be an entity itself and exist in a separate table?

What is the simplest and best practices way to handle this?

PS: I could simply reset the password with the database value each time prior to merging the User object, but that does not feel like the most elegant way.

Thanks
John


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 2:37 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
There are two ways to solve this problem related to context -

First - If you want to set password property as immutable (then you can't change password form User entity).

Map password property as update=false, so this property value will never will appear in Update statement of User.
Like


Code:
<properties name="password"update="false">


If your are use JPA then
@Column(name="PASSWORD",updatable="false")


Second- If you want to update password property whenever your change it. (Means password should be only be come in update statement, if you change the value of it).

Map the User class using dynamic-update="true". Then password column appear in the update statement of user table only when you change the value of password property of user class. If you set dynamic-update="true" in a class, Hibernate at run time find out what properties has change and then only changed property will appear in update statement.


Code:
<class name="User" table="user_table" dynamic-update="true"/>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.