Hibernate beginner help

Posted on 2011-10-24
Last Modified: 2012-05-12

Hello there,

I am reading a book on hibernate and i came across this sentence.can somebody please explain more about it.

Notice that we haven't inherited or implemented any type of class or interface. Thus,Hibernate will use reflection based on the JaveBean setter/getter methods to persist the object

Question by:zolf
    LVL 47

    Accepted Solution


    Reflection is API which allows to anlyze the structure of the class - to determine what are the
    variables and methods of the class - so for example with relection you can printout all properties
    of the class (variables which have setter and gtette methods)
    you can read more details here:

    when Hibernate deals wth entity (the class onjectys of which will be perssited)
    it is imporant to have amecghanism to dtermenie what are the properties of this class and then use this knowledge in order to persis this
    class, i.e. to persist the propwrties of the entity

    Therefore Hibernate makes heavty use of Java Reflection

    LVL 47

    Expert Comment


    Author Comment


    can you try to give me a more easier defination of reflection or what it does
    LVL 20

    Assisted Solution

    by:Sathish David Kumar N
    As per i Know i explain this .  you know POJO class .  POJO flied name ,hibernate property name are same . then you need not worry about result sets .

    select username from user_admin

    the result you want to set in list ,then you want itterate but here

    List<PojoClassName>=select username from user_admin

    it will directly assign username filed values other or null
    LVL 40

    Assisted Solution

    Its simple.
    When you specify hibernate mappings for each table with the class, then you simply mention which class member will be used for which table column. Since, those members are private, hibernate uses the class member names to construct the getter method name and setter method name, and invoke them using reflection APIs
    LVL 47

    Expert Comment


    Suppose you have some A.Class
    Relction provides method which allows to detrmine what are the names of the methods of theis class
    So I can basically say


    and I'll get array of string - methods names as they were written in the code
    and I can find those method names which start with "set" and which start with "get" and I can find what goes after set and get and thus find the names of properties
    LVL 40

    Assisted Solution

    And why would it invoke them is not tough to figure out. They do it for native query generation, query results processing so that they get converted to POJO objects, or simply  doing CRUD operations on your objects
    LVL 47

    Assisted Solution

    Reflection is a powerful thing - so when in the program you have an instance of the class - you can discover from that
    instance only, without needing the  source code of the class, all details about the class as if you would have the code for that class. And even invoke methods on this cinstance not
    knowing uinitially how they were named in the class and only getting it from the instance of the class. And suppose at certain place if the program you can encounter instances of different
    classes - then form instance itself you'll be able to discover what fields the class of each particular instance you are deiling with
    does have. And if someone adds aditional property to the class - you'll not need to
    change your code which analyzes this instance - because reflection would allow you to find the propwerties of a modified class
    and use them. So Reflection itself is very understandable thing and its use goes far beyond hibernate.

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    sameEnds challenge 25 55
    JKS to store upstart data 2 51
    scoresIncreasing challenge 10 47
    Java virtual machine monitoring tools 3 30
    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now