Hi,
I've a problem with mapping many-to-many relation.
My requirement is to find the menus with all their roles and menu_role properties.
I found some examples for normal many-to-many relation with 3 tables, in which the 3rd table contains only the foreign keys.
But in this scenario, in addition to the menu_id and role_id there are 2 more fields READ_FLAG and WRITE_FLAG in the MenuRole table.
There is a table called MENU which defines the menu properties.
The other table called ROLE which defines the role properties.
And the 3rd table called MENU_ROLE which defines the role properties (read, write, delete) on Menus. And the table descriptions are:
CREATE TABLE CS_MENU (
CS_MENU_ID NUMBER(10 , 0) NOT NULL,
NAME VARCHAR2(100) NOT NULL,
DISPLAY_NAME VARCHAR2(100)
);
-------------------------------------------------
CREATE TABLE CS_ROLE (
CS_ROLE_ID NUMBER(10 , 0) NOT NULL,
NAME VARCHAR2(30) NOT NULL,
);
------------------------------------------------
CREATE TABLE CS_MENU_ROLE (
CS_ROLE_ID NUMBER(10 , 0) NOT NULL,
CS_MENU_ID NUMBER(10 , 0) NOT NULL,
READ_ONLY_FLAG VARCHAR2(1) NOT NULL,
UPDATE_ONLY_FLAG VARCHAR2(1) NOT NULL,
DELETE_ONLY_FLAG VARCHAR2(1) NOT NULL
);
-------------------------------------------------
Now, I've written hibernate mapping files for the above entities as below.
Role.hm.xml:
--------------
Code:
<hibernate-mapping>
<class name="com.cvc.authenticateUser.cssecurity.hibernate.CsRole" table="CS_ROLE">
<id name="csRoleId" column="CS_ROLE_ID">
<generator class="increment"/>
</id>
<property name="name" column="NAME"/>
[b] <!-- How to map here with MenuRole table -->[/b]
</class>
</hibernate-mapping>
Menu.hbm.xml:
-----------------
Code:
<hibernate-mapping>
<class name="com.cvc.authenticateUser.cssecurity.hibernate.CsMenu" table="CS_MENU">
<id name="csMenuId" column="CS_MENU_ID">
<generator class="increment"/>
</id>
<property name="displayName" column="DISPLAY_NAME"/>
<property name="name" column="NAME"/>
[b]
<!-- How to map here with MenuRole table -->[/b]
</class>
</hibernate-mapping>
MenuRole.hbm.xml:
------------------------
Code:
<hibernate-mapping>
<class name="com.cvc.authenticateUser.cssecurity.hibernate.CsMenuRole" table="CS_MENU_ROLE">
[b] <!-- How to map here with Menu table -->
<!-- How to map here with Role table -->[/b]
<property name="readFlag" column="READ_FLAG"/>
<property name="writeFlag" column="WRITE_FLAG"/>
</class>
</hibernate-mapping>
----------------------------------------
My requirement is to find the menus with all their roles and menu_role properties.
I found some examples for normal many-to-many relation with 3 tables, in which the 3rd table contains only the foreign keys.
But in this scenario, in addition to the menu_id and role_id there are 2 more fields READ_FLAG and WRITE_FLAG in the MenuRole table.
I'm trying to find the proper mappings for the last 1 week. But nothing helps me to resolve this. I would appreciate if some one please let me know how to map this relation with many-to-many requirement.
Sorry for the bit lengthy post.
Thanks in advance,
Vel.