Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0
Problem:
I have a many to many relationship between USER and ROLE. Please find below the mapping files for USER and ROLE.
I need to add additional columns(GROUP, APP_ID) to the association table USER_ROLE .
Is it possible to add above fields (GROUP, APP_ID) to the SET or BAG which has many-to-many?
If it is can any one provide an example of mapping and POJO.
Following the database tables:
USER
_____________
*UID
NAME
DOB
_____________
______________
USER_ROLE
__________________
*USER_UID
*ROLE_RID
__________________
GROUP
APP_ID
__________________
___________
ROLE
_____________
*RID
NAME
DESC
_____________
Following mappings and client works well without new fields (GROUP, APP_ID)..
user.hbm.xml
============
<hibernate-mapping>
.......
<set name="roleList" table="USER_ROLE">
<key column="UID"/>
<many-to-many column="RID" class="Role"/>
</set>
</hibernate-mapping>
User.java
=========
public class User {
..
...
...
private Set roleList = new HashSet();
public Set getRoleList() {
return roleList;
}
public void setRoleList(Set roleList) {
roleList = roleList;
}
.....
.....
}
TestClient.java
===============
public class TestClient {
........
........
User user = (User) session.load(User.class, userId);
Role role = (Role) session.load(Role.class, roleId);
user.getRoleList().add(role);
.........
.......
}
Name and version of the database you are using: Oracle 9i
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html[/img]