This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!