Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does hibernate use private methods ?

 
Saumya Nair
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
 
Paul Sturrock
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