-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Persisting many-to-many relation
PostPosted: Fri Apr 08, 2005 10:29 am 
Newbie

Joined: Tue Mar 01, 2005 7:10 am
Posts: 1
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 Code
Code:
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.