aspose file tools*
The moose likes Object Relational Mapping and the fly likes How does hibernate use private methods ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How does hibernate use private methods ?" Watch "How does hibernate use private methods ?" New topic
Author

How does hibernate use private methods ?

Saumya Nair
Ranch Hand

Joined: Apr 25, 2006
Posts: 34
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
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


In plain java, we can't access the private methods outside the defined class

Yes we can, if by "plain java" you mean the core APIs. The Reflection API includes a way to change the access flag for fields and methods (look at the setAccessable() method). I can't say whether Hibernate does it this way (have a look in the code and you should be able to find out) but its probable they do.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How does hibernate use private methods ?