-->
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: Using field access strategy: bad idea?
PostPosted: Wed Dec 07, 2005 1:12 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
I would like to have NHibernate get & set our entity values directly through their fields, rather than through their properties. It would seem to offer better performance.

More importantly, though, it would allow entities to get loaded by NHibernate that have values considered "illegal" by the property setter, so that they could be cleaned without resorting to direct SQL. These "illegal" values could occur even if only NHibernate saved data to the database, if validation rules in a property setter were tightened up after some entities were already persisted.

Members of our design team are very concerned about letting NHibernate access private fields through reflection. They say Microsoft has admitted that this capability is a bug and will eventually be removed. Is this true? Is anyone else using field access rather than property access?

The fact that this feature has existed for a long time in Java suggests to me that the Java world does not consider access to private fields through reflection a "bug", and has no intention of removing the capability ...


Last edited by Nels_P_Olsen on Wed Dec 07, 2005 6:19 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 1:25 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
Oh yeah -- another reason I'd like to use field access rather than property access is that then you can expose the entity Ids as read-only properties. If we have to set up our mappings to use property access, then we have to put setters on the Id properties, and have them throw exceptions if the previous value is not null and not equal to the value to set. (Using "no-setter" won't help, since that still accesses private fields through reflection, which is supposedly going to be taken away by Microsoft ...)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 5:10 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
I can not help you, however, I really can not believe that setting private fields through reflection is a 'bug'. When using reflection you even have bindingflags for private access and this is well documented.

Taking away this feature would break almost all non-trivial applications.

Therefor, I would not think twice about it, and just use reflection.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 6:16 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Hmm, private member reflection is already controlled by security settings, so I don't understand why it should be completely removed. Do you have any link where somebody from MS says the capability is going away?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 11:45 am 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
That's what I think, too. I'll have to check with the other members on my design team to find out what all the fuss is about :?


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.