-->
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.  [ 3 posts ] 
Author Message
 Post subject: Direct Field Access vs. Accessors
PostPosted: Thu Nov 04, 2004 6:37 pm 
Newbie

Joined: Thu Nov 04, 2004 6:00 pm
Posts: 8
Location: Palo Alto, CA
I've recently begun a project to convert an EJB application (session and entity beans) to Spring/Hibernate and have an architectural question for those that have blazed ahead.

I've read in a few places that using accessor methods is recommended over direct field access for the mappings. However, this makes my public accessors less elegant than I had hoped. When a client calls a setter, I want to apply validation checks (not null, cannot overwrite existing non-null value, etc), but I don't want those to interfere with Hibernate loading an object from the database.

One solution I see is to have two sets of accessors: one set for clients and another stripped-down set for Hibernate. However, it seems no different at that point from using direct field access.

What have others found with both methods, and are there any particular gotchas when using direct field access?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 04, 2004 6:40 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Nope, no gotchas.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 04, 2004 7:18 pm 
Newbie

Joined: Thu Nov 04, 2004 6:00 pm
Posts: 8
Location: Palo Alto, CA
Wow! Thanks for the quick reply. I've only read bits and pieces of HiA so far (enough to get started on my project), and only found this one reference:

"Sometimes we would prefer that this validation not occur when Hibernate is initializing a newly loaded object. In that case, it might make sense to tell Hibernate to directly access the instance variables." (p. 74)

But there was no discussion on whether or not doing so is a Good Thing(tm) design-wise. I guess that there aren't any problems with it is good enough.

BTW, I've found the book very helpful so far, so thanks again![/i]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.