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.  [ 11 posts ] 
Author Message
 Post subject: Not persisting all fields of an object.
PostPosted: Wed Mar 01, 2006 6:20 am 
Beginner
Beginner

Joined: Mon Dec 26, 2005 4:55 pm
Posts: 28
Hello,

I am currently working on a Hibernate system. I have an object that stores the password of a client. However this objet also stores the email address of this client.

My problem is that each time the user changes his email he has to change the password. If he leaves the password empty, it will ba saved as an empty string, since the whole object is being saved.

Is there a way how I can tell hibernate to not save the password field on some occasions?

The other solution for me is to save the password inside another table. However that would lead me to use another table in the database and another object, plus some re-write of the system,

so any other solution is more then welcome.

Thanks and Regards
sim085


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 01, 2006 7:00 am 
Regular
Regular

Joined: Wed Feb 08, 2006 3:59 pm
Posts: 75
Simple solution : not to set the password as null (nor "") if the user leaves the password empty. Just add a changePassword() method, if the password is empty, it does nothing, if not is calls the setter.


Top
 Profile  
 
 Post subject: Password
PostPosted: Wed Mar 01, 2006 7:49 am 
Newbie

Joined: Sat Oct 29, 2005 1:23 pm
Posts: 15
Location: England
That would mean that the password is brought down into the domain objects even if it is not required, this breaks good security practices.

Security data such as identification and authentication keys should be stored seperatly to the other business domain classes, so a seperate table would be a better architecture.

The previous persons post would be suitable if the field was anything other than a password though.

_________________
Jamie Cash
eCommerce Consultancy Limited
The eSecurity Experts


Top
 Profile  
 
 Post subject: Re: Password
PostPosted: Wed Mar 01, 2006 8:00 am 
Beginner
Beginner

Joined: Mon Dec 26, 2005 4:55 pm
Posts: 28
[quote]Simple solution : not to set the password as null (nor "") if the user leaves the password empty. Just add a changePassword() method, if the password is empty, it does nothing, if not is calls the setter.[/quote]

However if the user does not change the password, but changes the email, then it would mean that neither the email would be saved since both om them are in the same object.


[quote]Security data such as identification and authentication keys should be stored seperatly to the other business domain classes, so a seperate table would be a better architecture[/quote]

Yes I know that it is not a good design practice. So you think it is ok to have a table with just passwords in it?

thanks and regards
sim085


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 01, 2006 9:39 am 
Regular
Regular

Joined: Wed Feb 08, 2006 3:59 pm
Posts: 75
My answer wasn't clear, I meant when a user changes its email, call setEmail() (so email will be saved) AND call changePassword(). The changePassword() method won't set the password attribute if its argument is empty or null (so password will only be saved if not blank).

Of course I agree too that it's not a good practice to let the password travel to the client.


Top
 Profile  
 
 Post subject: Password
PostPosted: Wed Mar 01, 2006 10:42 am 
Newbie

Joined: Sat Oct 29, 2005 1:23 pm
Posts: 15
Location: England
Yes, it would be a better design to hold the passwords in a seperate table.

_________________
Jamie Cash
eCommerce Consultancy Limited
The eSecurity Experts


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 7:09 am 
Beginner
Beginner

Joined: Mon Dec 26, 2005 4:55 pm
Posts: 28
[quote]Of course I agree too that it's not a good practice to let the password travel to the client.[/quote]

I am not allowing the password to go back to the user. That is why it is being saved as blank.

[quote]My answer wasn't clear, I meant when a user changes its email, call setEmail() (so email will be saved) AND call changePassword(). The changePassword() method won't set the password attribute if its argument is empty or null (so password will only be saved if not blank).
[/quote]

So you are telling me that if I set the password as null, then even if both password and email are fields in the same object it would still save only the email?

or I also have to add something in my mapping file?

regards
sim085


Top
 Profile  
 
 Post subject: Password
PostPosted: Thu Mar 02, 2006 10:06 am 
Newbie

Joined: Sat Oct 29, 2005 1:23 pm
Posts: 15
Location: England
If you set password to null, then it will be saved as null, If you change the state of a domain object, then all properties / fields in that object will be saved.

If you were to split the authentication data away from the user data, and set cascade to no, the password data will not be retrieved with the user data. You will then need to make a call specifically to get the password data when you require it. This approach will mean that your password data will never exist outsied of your session bean or server side tier, and therefore you will not need to set it to null when returning the user data to the client.

The authentication data class will have a link back to the user, but not the other way around.

I hope this helps.

_________________
Jamie Cash
eCommerce Consultancy Limited
The eSecurity Experts


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 12:04 pm 
Beginner
Beginner

Joined: Mon Dec 26, 2005 4:55 pm
Posts: 28
Yes it helps a lot thanks :)

I had done something like that with the Contact class and Address class. However I always saved the data of both.

I always tought that cascade is something about delete not saving however.

Also is there a way to sometimes make cascade is true and some othertimes make cascade is false. Or this is something in the hbm file (i.e. I set it up with xDoclet).

regards
sim085


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 4:18 am 
Newbie

Joined: Sat Oct 29, 2005 1:23 pm
Posts: 15
Location: England
This is an hbm property. You cannot set it manually unless you reconfigure Hibernate using Java, but this is out of my realms of expertiese.

Could you rank my reply?

_________________
Jamie Cash
eCommerce Consultancy Limited
The eSecurity Experts


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 7:23 am 
Beginner
Beginner

Joined: Mon Dec 26, 2005 4:55 pm
Posts: 28
Sorry :$ did not know about that feature in this forum :)

Thanks for all the help, I will try to see how to do it :)
Thanks again

regards
sim085


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.