File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Hibernate Many to ManyMapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Many to ManyMapping" Watch "Hibernate Many to ManyMapping" New topic

Hibernate Many to ManyMapping

meghna kapoor

Joined: Jul 07, 2011
Posts: 1

I am developing an application in Spring and has integrated it with Hibernate.
I have a User table, UserGroup table with following schema
User has employeeId as primary key and also has a set like this
<set name="usergrp" table="user_group" cascade="all">
<key column="employeeId" />
<many-to-many column="id" class="in.netambit.domain.UserGroup" />
And have UserGroup table with grpId and grpName
I have achieved the many to many mapping that a user can have mutiple usergroups and multiple user can have same group.

Here are the tables
employeeId employeeName
admin Meghna
kuldeep kuldeep
richa Richa

UserGroup table
userId userGrpName
1 'Admin'
2 'Supervisor'
3 'General'

And due to this mapping i got a user_group table in database which contains the relationship between the two onjects


employeeId id
admin 1
richa 3
kuldeep 2

Now this user_group has all the entries of user who are supervisors

Now i want to achieve many to many relationship between user and supervisor
i know this can be achieved if i have the supervisor table but i dont have this. All the user who are supervisors are mapped in user_group table. Which is not an object in Hibernate .
i want to have a single table assigned_supervisor with user and supervisor relationship

like this
employeeId supId
richa kuldeep

here richa is the employee id of a general user and he is assigned a supervisor with employee id kuldeep

How to achieve this?

this is very urgent

Consider Paul's rocket mass heater.
subject: Hibernate Many to ManyMapping
It's not a secret anymore!