• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate !!!! mapping help

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    ranger
    Posts: 17347
    11
    Mac IntelliJ IDE Spring
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    Ranch Hand
    Posts: 379
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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).
     
    Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic