-->
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.  [ 5 posts ] 
Author Message
 Post subject: What is the tradeoff when access="field"?
PostPosted: Mon Jan 31, 2005 1:08 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
Is there any reason why this option is not the default? I find that the more I want to make my domain objects responsible for business rules and validation, the more I turn this option on to make sure this code does not get executed when hibernates needs to get and set values. What is the trade off for setting this option on all the time?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 31, 2005 3:30 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
We use access="field" as our default for exactly the same reason - we don't want developers business logic in the getters and setters being triggered during persistence.

I guess the drawback would be the extensive use of Reflection (and/or CGLIB, or however Hibernate accesses the private attributes?) to access the private attributes every time a persistence object is retrieved/stored?

Kevin Hooke


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 31, 2005 5:01 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
But doesn't Hibernate use reflection to call the get/set methods as well? I guess I'm curious what the difference is, if any.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 31, 2005 5:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Nope, reflection is only used for direct field access.

And no, I don't think there is realistically any performence difference on a modern JVM.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 31, 2005 6:43 pm 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
Another difference is that the code in your mapped objects will have to account for the fact that fields get set by code outside of the class. This means that an instance can be in a state that cannot be produced by the constructors and setters. This can make for some pretty strange bugs.

I've used ORMs that do both, and I prefer Hibernate's default behavior. I also prefer to put validation logic in business session objects. In the end, it's just a more maintenance friendly design, IMHO.


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