-->
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: How does hibernate use private accessor methods
PostPosted: Wed May 24, 2006 10:47 am 
Newbie

Joined: Thu Apr 20, 2006 3:36 am
Posts: 13
hi all ,


I have a query.. Its written in hibernate's document that hibernate can access even private & protected methods. It goes as --- " we usually don't manipulate the identity of an object, hence the setter method should be private. Only Hibernate will assign identifiers when an object is saved. You can see that Hibernate can access public, private, and protected accessor methods, as well as (public, private, protected) fields directly."

In plain java, we can't access the private methods outside the defined class. Then how is it that hibernate is able to access any of the accessor methods.


Regards,
Saumya


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 8:01 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Hibernate uses CGLib to create proxy classes that extend your class. These proxy classes are created in the same package, and exploit all sorts of neat features of reflection and byte-code hackery. Don't try it at home, folks.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 27, 2006 3:54 am 
Beginner
Beginner

Joined: Sat Dec 17, 2005 1:24 pm
Posts: 42
Location: Berlin, Germany
Hi!

When using reflection, you can actually modify the accessibility of a class element (field or method) [see http://java.sun.com/j2se/1.4.2/docs/api/java/lang/reflect/AccessibleObject.html#setAccessible(boolean)].

As it has been set; there are very rare legitimate use cases for this!

All the best,

René


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.