Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0
Mapping documents:
Code:
<hibernate-mapping>
<class
name="re.persistance.PermissionsGroup"
table="PermissionsGroup"
dynamic-update="true"
dynamic-insert="false"
>
<id
name="permissionsGroupId"
column="permissionsGroupId"
type="java.lang.Integer"
>
<generator class="identity">
</generator>
</id>
<property
name="permissionsGroupIdn"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="permissionsGroupIdn"
length="32"
not-null="true"
/>
<property
name="permissionsGroupDesc"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="permissionsGroupDesc"
length="255"
not-null="false"
/>
<bag
name="permissions"
table="permissionsgroupspermissions"
lazy="true"
inverse="true"
cascade="save-update"
outer-join="true"
>
<key column="permissionsGroupId"></key>
<many-to-many
class="re.persistance.Permission"
column="permissionId"
outer-join="true"
/>
</bag>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PermissionsGroup.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Run CodeCode:
Session s = sessionFactory.openSession();
t = s.beginTransaction();
Permission permission = new Permission();
permission.setPermissionIdn("CreateAdverisement");
permission.setPermissionDesc("Permission to create Adverisement");
PermissionsGroup permissionsGroup = new PermissionsGroup();
permissionsGroup.setPermissionsGroupIdn("Group 1");
permissionsGroup.setPermissionsGroupDesc("Group 1");
permissionsGroup.addPermission(permission);
s.save(permissionsGroup);
t.commit();
s.close();
Name and version of the database:
Postgres 8.0
Problem:
When I save PermissionGroups I want that this code insert 3 rows to database, to 3 tables: Permission, PermissionsGroup, permissionsgroupspermissions.
Now hibernate save only to Permission and PermissionsGroup.
Ralation betwen PermissionsGroup and Permission don`t be save.
What I do wrong?
Thanks for help!
Konrad