• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

Hibernate beginner help


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
zolf
Asked:
zolf
  • 4
  • 2
  • 2
  • +1
5 Solutions
 
for_yanCommented:

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
 
zolfAuthor Commented:

can you try to give me a more easier defination of reflection or what it does
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Sathish David Kumar NArchitectCommented:
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
 
Gurvinder Pal SinghCommented:
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
 
for_yanCommented:


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
 
Gurvinder Pal SinghCommented:
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
 
for_yanCommented:
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
 
zolfAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now