Get all updates of Java4s
Follow Us: Email Newsletter

Mapping And Configuration Files In Hibernate

Hibernate » On May 4, 2011 { 48 Comments } By Sivateja

Mapping and Configuration are very familiar keywords we used to here in the hibernate, every hibernate program must need these 2 xml files.

Mapping:

  • Mapping file is the heart of hibernate application.
  • Every ORM tool needs this mapping, mapping is the mechanism of placing an object properties into column’s of a table.
  • Mapping can be given to an ORM tool either in the form of an XML or in the form of the annotations.
  • The mapping file contains mapping from a pojo class name to a table name and pojo class variable names to table column names.
  • While writing an hibernate application, we can construct one or more mapping files, mean a hibernate application can contain any number of  mapping files.

generally an object contains 3 properties like

  • Identity (Object Name)
  • State (Object values)
  • Behavior (Object Methods)

But while storing an object into the database, we need to store only the values(State) right ? but how to avoid identity, behavior.. its not possible. In order to inform what value of an object has to be stored in what column of the table, will be taking care by the mapping,  actually mapping can be done using 2 ways,

  • XML
  • Annotations.

Actually annotations are introduced into java from JDK 1.5.

Syntax Of Mapping xml:

Configuration:

Configuration is the file loaded into an hibernate application when working with hibernate, this configuration file contains 3 types of information..

  • Connection Properties
  • Hibernate Properties
  • Mapping file name(s)

We must create one configuration file for each database we are going to use, suppose if we want to connect with 2 databases, like Oracle, MySql, then we must create 2 configuration files.

No. of databases we are using  = That many number of configuration files

We can write this configuration in 2 ways…

  • xml
  • By writing Properties file.  We don’t have annotations here, actually in hibernate 1, 2.x we defined this configuration file by writing .properties file, but from 3.x xml came into picture.

so, finally

Mapping –> xml, annotations
Configuration –> xml, .properties (old style)

 

Syntax Of Configuration xml:

But XML files are always recommended to work.

You Might Also Like

  ♦ About Author ♦

Java4s_Author
sivateja@java4s.com
Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

48 Responses to “Mapping And Configuration Files In Hibernate”
  1. ankit patel says:

    very nice tutorials…….
    Thanks a lot…

  2. ReddyPrasad says:

    Really a simple and nice tutorial to learn in easily Hibernate. Thanks a lot. I am going to bookmark it.

  3. Mohd arshad says:

    Excellent way of explaining..quite easy and understandable… hope I am going to learn hibernate this time :)

  4. satish says:

    can u plz explain the steps of execution?i mean is hibernate.cfg.xml file is read first or xxx.hbm.xml file is read first?

  5. Zulfiqar Ali says:

    Nice One I appreciate this work

  6. Akbar says:

    simple and easily understandable to every one …
    thank u for giving such a great tutorial….

  7. TAUFIK says:

    Very Useful Site And feelling like Very Easy to Learn

  8. Rajesh says:

    Thanks Bro. It made my life easy.
    Its Really a Good job.

  9. samba says:

    thanks to providing this kind of easy learning process.according to as you said suppose if we work with two different database we need to take two different configuration file.why we cant maintain in single file with two session factory configuration in single file.any how thanks to provide best tutorial.

  10. Sireesha says:

    Which version of hibernate we should download to run through the trail examples mentioned in the website

  11. amit jain says:

    Very Nice….. I appreciate this work…
    thank you very much..

  12. Sonu says:

    Superb….No words !!

  13. Venkat says:

    Thanks for your wonderful site.
    As earlier you mentioned in hibernate JDBC problems
    ” here as a programmer we must close the connection, or we may get a chance to get our of connections message…!” but in hibernate also we are closing Database connections..So even this would be problem in hibernate also… can you clarify me?
    thanks in advance

  14. Shakthi says:

    tutorials are very useful…

  15. Chetan says:

    nice tutorial ………thank you

  16. Durga Bhavani says:

    Hi,
    please develop the jsf tutorial as early as possible.we are waiting for that.

  17. Sumanth says:

    Hi Sivateja Kandula,

    This tutotial is very nice. Now I want To Connect With 2 Databases For Example MySql, Oracle.Can You Provide how to configure this..??

  18. creditto says:

    Hai Bro…

    Very Useful Site And feelling like Very Easy to Learn

  19. Srinivas says:

    No need of any training… This content is enough to learn Hibernate

  20. amit_0 says:

    thanks for your tutorials they really helped me….

  21. sandip says:

    wow really good sir, it’s very simple for me thanks sir

  22. Edison OKPE says:

    Great work ! hibernate simplified Thanks

  23. Lalchand Mali says:

    Great Tutorial..
    I have read more tutorial but found this one is great.

    Thanks a lot

  24. jagadeesh says:

    Niced tutorial ,Gr8 work

  25. bala says:

    very simple and easy to understand syntax’s

  26. rajnishpatel says:

    thank you very much for writing hibernate tutorials ….its easy to understand again i want to say thanks a lot,its very very helpful ………….

  27. Thaqi says:

    Is there any PDF doc for this?

  28. Devendra says:

    This is very nice tutorial website for beginner as well as professional.

    Thanks Sivateja Kandula for your outstanding efforts

  29. suresh says:

    very good site to learn every topic

  30. Anbarasu says:

    Thank u so much..

  31. srinivas says:

    i have one doubt is it possible to write combination of hbm and annotations for single programe.

  32. Sudhakar says:

    Hai Sivateja,
    Your explanation very good…
    Thanks…

  33. Mallikarjun Patil says:

    Hi Sivateja,

    Very helpfull for beginners and experience people, keep posting help full java related technology.

    Thanks,

  34. Prasanna says:

    Very nice and understandable tutorial. Thank you sooooooo much…

  35. Nagendra says:

    very nice this hibernate tutorial its very simplest explanations..

  36. pradeep says:

    any external mapping is needed wheather we use annotations please explain in depth while using the annotations

  37. chirag baraiya says:

    sir this is very nice tutorial Please explain me Getters and Setters method with example i can’t understand

  38. priyanka says:

    Can we give mapping file name other than .hbm.xml extension.

  39. Abdul says:

    Excellent work….

    Hibernate simplified….

    Thanks bro

  40. Rahul Gupta says:

    nice tutorial

  41. shailesh says:

    Easy to understand language..very good work!

  42. suseela says:

    awesom site

  43. Sandeep Saini says:

    Sir why mostly XML is considered in place of .properties file.

  44. Animesh says:

    Can you please give an example of mapping file in terms of annotations ?
    syntax of Mapping Annotations !…

  45. ved prakash says:

    superb.

  46. Rajesh says:

    Simply Superb…

  47. k.s.Banu says:

    super nd simplly explanation

  48. Vijayalaxmi says:

    This tutorial is very simple to learn hibernate…
    Thank u Sir

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
Upcoming
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2016 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.