• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Working Example Needed..

 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Hibernate Reference has examples related to these.
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic