views:

82

answers:

0

Hi there,

I'm pretty new to hibernate and this is my first posting in here. I want to create a mapping for a somehow complex scenario and I just don't get it.

I have a 'group' entity where I want to store information about 'orgUnits' and 'divisions', a group member has access to. One group can contain zero to many orgUnits and the orgUnits can contain zero to many divisions. The main problem is that the divisions could vary in different groups for the same orgUnits.

So:
group1 could give access to (orgUnit1 and div1 + div2) + (orgUnit2 and div1) + other combinations
while
group2 could give access only to orgUnit1 and only div2
and
group3 could give access only to orgUnit2 (without further specifications for divs)

I set up a hbm file for the group that contains a map for a new object for 'groupOrgUnits':

<map name="groupOrgUnits" inverse="true" cascade="all-delete-orphan">
<key column="groupName" foreign-key="FK_GROUP_ORGUNIT_GROUPNAME" not-null="true"/>
<map-key-many-to-many column="orgUnitNo" 
    class="OrgUnit" 
    foreign-key="FK_GROUP_ORGUNIT_ORGNO"/>
<one-to-many class="GroupOrgUnit"/>

I also put a class for the GroupOrgUnit inside the group.hbm.xml file which contains a composite key and a set for the 'divisions' I want to assign to the groupOrgUnits:

<class name="GroupOrgUnit" table="GROUP_ORGUNIT">

<composite-id name="groupOrgUnitIdentifier" class="GroupOrgUnitIdentifier">
    <key-property name="groupName" type="string" length="40" column="GROUPNAME"/>
    <key-property name="OrgUnitNo" type="string" length="4" column="ORGUNITNO"/>
</composite-id>

<version name="dbVersion"           unsaved-value="negative"/>

<set name="divisions" table="GROUP_ORGUNIT_DIV">
    <key not-null="true" foreign-key="FK_GROUP_ORGUNIT_DIV" unique="true">
        <column name="GROUPNAME" not-null="true"/>
        <column name="ORGUNITNO" not-null="true"/>
    </key>
    <many-to-many class="Division" column="NAME"/>
</set>

Hibernate now makes two tables GROUP_ORGUNIT and GROUP_ORGUNIT_DIV where all columns are a part of the primary key.

All works fine when I try to fill these tables with content and I'm able to remove GroupOrgUnitDivs from the GROUP_ORGUNIT_DIV table BUT I am not able to remove GroupOrgUnits from the GROUP_ORGUNIT table. Spring/Hibernate takes the update content to the DataBinder and just returns with an unchanged (not updated) entity.

I guess that the 'inverse="true"' parameter has to do with the problem but if I remove this parameter, an error occurs which tells me to use the 'insert="true"' and 'update="true"' parameters. Unfortunately they are not available for my used hibernate tags.

So if someone could help me, this would be realy nice.

Thanks in advance!

Greetings, Gernot

related questions