This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Working Example Needed.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Working Example Needed.." Watch "Working Example Needed.." New topic
Author

Working Example Needed..

Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi Ranchers,
Can you provide me a working example in hibernate for the below ?




One-Many Mapping
Many-One Mapping
Many-Many Mapping



Help provided with regards to example will be appreicated.

--
Deepak Lal


When The Going Gets Tougher,The Tougher gets Going
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10240
    
168

The Hibernate Reference has examples related to these.


[My Blog] [JavaRanch Journal]
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi Jaikiran,
i have gone through the website,but can you give me some concrete examples(one-Many,Many-Many,Many-One) of real time scenario where it is implemented frequently.

Help provided will be highly appreciated.

--
Deepak Lal
Engin OKUCU
Greenhorn

Joined: Jun 29, 2007
Posts: 13
Hi Deepak,

Shrotly i can give an example that i think every time for these scenarios :

one-to-many : a Building may have a lot apartement

public class Building{
Set<Apartement> setApart = new HashSet<Apartement>
}

[B]many-to-one[/B] : all the apartements in a building belongs to only 1 building.

public class Apartement{
Building building = new Building();
}


For many-to-many, i can give you the example with User & Group. Think like in Windows when you create an account. A user may be an Administrator & Guest . There are not only one user using the windows of course. At the same time which means '1 or several users could
belongs more than 1 groups. --> a user with many groups.
In the opposite side , it's the same. 'A group may have got 1 or several users'.--> a group with many users.

public class Group{
Set<Group> setUser = new HashSet<Group>();
}

public class User{
Set<Group> setUser = new HashSet<Group>();
}

It's clear i hope.
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi All,
i have understood this concept now,but you can you tell me the implementation of the same in Hibernate.I'm not asking the definiitons of Mappings.


Can you give me Examples of definitons in hbm.xml file and relevant java files for the below mappings ::
One-Many Mapping,
Many-Many Mapping,
Many-One Mapping.


Please provide me examples with respect to Hibernate,definiton of hbm.xml file's and their relevant java files.

--
Deepak Lal
Engin OKUCU
Greenhorn

Joined: Jun 29, 2007
Posts: 13
Deepak,

I'm wondering if you spent time as Jaikiran mentionned you in the Hibernate Reference. I'm really doing nearly the parrot from this web site, it is well explained there.
And from my example you should be able to write the mapping files.
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi Ranchers,
I'm new to hibernate and If you can provide me with the logic for the hbm.xml and relevant java files.help provided will be highly appreciated.

--
Deepak Lal
[ November 13, 2008: Message edited by: Deepak Lal ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Working Example Needed..