This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I use the trim-method to get always the trimmed version of my name (that means all blanks will be deleted), when I retrieve this field from the database.
Should I do the trim in the getter or setter?
The problem is, when I do the trim in the getter, then JPA/Hibernate wants to update all these trimmed fields. I do not want that. I only want avoid to call everytime the trim-method from my session-Bean when I get char-fields. Any suggestions? [ December 04, 2008: Message edited by: nimo frey ]
Does data come from client side? Do you have validation code on server end? If so, instead of trimming the String in the setter method itself, if you put that inside validating method that returns desired trimmed string (or char array), it would be good.
Lets see what others say here.
Joined: Jun 28, 2008
yes, exactly. I use server-side-validation:
So, doing trim in getter resolves to a validation-failure.
So I have to do the trim in the validator, also?
But I do not want to update every row only because of the trimmed version of the field and I do not want to clutter my session-beans with trims for every field..hmm