Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate !!!! mapping help

 
Nisejava Duram
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can someone save me the rigour of understanding hibernate?

I just need one working many-one mapping example, with both the xml files and the related java code.

Can someone send me a sample code or direct me to a good link or a book
Also I am unable to understand the difference between unidirectional and bidirectional mapping

I am a newbie to hibernate

Thanks
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Nisejava.

You haven't really given us any information on where you are with Hibernate yet?

  • Have you set up Hibernate?
  • Do you have a database?
  • Do you have JDBC drivers?
  • Have you downloaded the Hibernate core module and the required dependencies?
  • Is this a web based application or a stand alone app?


  • I have a few free tutorials on my website that you might want to look at. First, get things set up on your computer. Second, verify your installation. Third, figure out how to do very simple CRUD operations with one table. And then, move into mapping associations. If you jump in head first with a shallow knowledge of Hibernate, you'll be in trouble.

    Here's a good place to start: How to Set Up and Configure Hibernate

    Good luck! Let us know how you do. And if you run into any problems, let us know and we'll try our best to help you out.

    -Cameron McKenzie
     
    Nisejava Duram
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,

    Thanks for taking the time to reply.
    I have set up the Hibernate environment in Eclipse.
    I have the databse drivers and have been successfully able to persist a single POJO in the database.

    Where I am getting lost is the mapping part. I have not been able to find a link which gives me a clear lucid example.

    I was also planning to get a copy of your book. Only thing the description of your book said that the book has not used the xml mapping files, since it is outdated.
    However a lot of projects out there would most probably be still using the xml mapping files and I thought that understanding that thoroughly is important to clear one of the hibernate interviews to get into a project.

    Can you refer me to a suitable example, link, book
    Thanks again for all help

    Nise
     
    Mark Spritzler
    ranger
    Sheriff
    Posts: 17278
    6
    IntelliJ IDE Mac Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    For bi-directional this is the exact mapping.
    http://www.hibernate.org/hib_docs/v3/reference/en/html/associations.html#assoc-bidirectional-m21

    The difference between uni and bi is based on the Java Objects. Do both Java objects have references to each other. So two classes Parent and Child, does Parent have a Collection of Child objects, and at the same time the Child has a reference to its Parent object. If so, then it is bi-directional. If just one side has a reference then it is uni-directional.

    Mark
     
    Nise Duram
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Mark.

    However I have some doubts there.
    In the example shown.

    I understand that the code for Address.java should have
    getPersons()
    setPersons(Person p)

    will there be a getAddress and setAddress in People.java

    ALS0

    <set name="people" inverse="true">
    <key column="addressId"/>
    <one-to-many class="Person"/>
    </set>

    also in this code, what does this <key column="addressId"/> refer to

    can you just explain a little more what exactly is this set thing...

    thanks

    nise
     
    Nise Duram
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,

    I know my question maybe a little trivial but i would really appreciate if someone can help me with a slightly clear explanation to the question above.

    many thanks
     
    Sathya Srinivasan
    Ranch Hand
    Posts: 379
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Since it's bi-directional, you will have accessor methods in both classes. The key refers to the association of primary key from one table to another.

    The best option for you would be to take up a book like Hibernate In Action, which tends to be a little more descriptive than the default documentation (and also contains some diagrams to help explain the concepts).
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic