aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate !!!! mapping help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate !!!! mapping help" Watch "Hibernate !!!! mapping help" New topic
Author

Hibernate !!!! mapping help

Nisejava Duram
Greenhorn

Joined: Jul 04, 2008
Posts: 7
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

Joined: Aug 26, 2006
Posts: 4968
    
    1

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

    Joined: Jul 04, 2008
    Posts: 7
    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

    Joined: Feb 05, 2001
    Posts: 17249
        
        6

    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


    Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
    How to Ask Questions the Smart Way FAQ
    Nise Duram
    Greenhorn

    Joined: Jun 15, 2008
    Posts: 3
    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

    Joined: Jun 15, 2008
    Posts: 3
    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

    Joined: Jan 29, 2002
    Posts: 379
    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).


    Cheers, Sathya Srinivasan - SCJP 1.2, SCWCD 1.2, SCMAD 1.0
    Co-Author of Whizlabs SCMAD Certification Exam Simulator and SCMAD Exam Guide Book
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Hibernate !!!! mapping help
     
    Similar Threads
    Help me knock off StaleStateException
    tools of the hibernator
    SQLGrammarException
    how to set date format in hibernate mapping
    how to use IBatis to paging in jsp?