[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Hibernate beginner help

Posted on 2011-10-24
9
Medium Priority
?
336 Views
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

cheers
Zolf
0
Comment
Question by:zolf
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 1400 total points
ID: 37016333

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:
http://download.oracle.com/javase/tutorial/reflect/

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


0
 
LVL 47

Expert Comment

by:for_yan
ID: 37016337
0
 

Author Comment

by:zolf
ID: 37016437

can you try to give me a more easier defination of reflection or what it does
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 20

Assisted Solution

by:Sathish David Kumar N
Sathish David  Kumar N earned 200 total points
ID: 37016441
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 .

eg:
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
0
 
LVL 40

Assisted Solution

by:Gurvinder Pal Singh
Gurvinder Pal Singh earned 400 total points
ID: 37016455
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37016457


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

a.getClas().getMethodNames()

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
0
 
LVL 40

Assisted Solution

by:Gurvinder Pal Singh
Gurvinder Pal Singh earned 400 total points
ID: 37016465
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
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 1400 total points
ID: 37016659
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.
0
 

Author Closing Comment

by:zolf
ID: 37018741
thanks
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

873 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