This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Kubernetes in Action and have Marko Luksa on-line!
See this thread for details.
Win a copy of Kubernetes in Action this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How does hibernate use private methods ?  RSS feed

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!