-->
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: Many-to-Many relationship not saving
PostPosted: Fri Apr 21, 2006 3:22 am 
Newbie

Joined: Tue Apr 04, 2006 10:58 pm
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1
Mapping documents:
Code:
<hibernate-mapping
>
    <class
        name="com.amlforum.entities.User"
        table="users"
    >

        <id
            name="id"
            column="id"
            type="java.lang.Long"
        >
            <generator class="native">
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-User.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>

        <property
            name="avatar"
            type="java.lang.String"
            update="true"
            insert="true"
            column="avatar"
            length="255"
        />

        <property
            name="email"
            type="java.lang.String"
            update="true"
            insert="true"
            column="email"
            length="255"
        />

        <set
            name="groups"
            table="userGroup"
            lazy="true"
            inverse="true"
            cascade="all"
            sort="unsorted"
        >

            <key
                column="userId"
            >
            </key>

            <many-to-many
                class="com.amlforum.entities.Group"
                column="groupId"
                outer-join="auto"
             />

        </set>

        <property
            name="password"
            type="java.lang.String"
            update="true"
            insert="true"
            column="password"
            length="50"
        />

        <many-to-one
            name="rank"
            class="com.amlforum.entities.Rank"
            cascade="all"
            outer-join="auto"
            update="true"
            insert="true"
            column="rankId"
        />

        <property
            name="signature"
            type="java.lang.String"
            update="true"
            insert="true"
        >
            <column
                name="signature"
                sql-type="TEXT"
            />
        </property>

        <property
            name="status"
            type="byte"
            update="true"
            insert="true"
            column="status"
        />

        <property
            name="username"
            type="java.lang.String"
            update="true"
            insert="true"
            column="username"
            length="50"
        />

        <property
            name="createdDate"
            type="java.util.Date"
            update="true"
            insert="true"
            column="createdDate"
        />

        <property
            name="modifiedDate"
            type="java.util.Date"
            update="true"
            insert="true"
            column="modifiedDate"
        />

        <property
            name="homepage"
            type="java.lang.String"
            update="true"
            insert="true"
            column="homepage"
            length="200"
        />

        <property
            name="imAol"
            type="java.lang.String"
            update="true"
            insert="true"
            column="imAol"
            length="20"
        />

        <property
            name="imIcq"
            type="java.lang.String"
            update="true"
            insert="true"
            column="imIcq"
            length="20"
        />

        <property
            name="imMsn"
            type="java.lang.String"
            update="true"
            insert="true"
            column="imMsn"
            length="20"
        />

        <property
            name="imYahoo"
            type="java.lang.String"
            update="true"
            insert="true"
            column="imYahoo"
            length="20"
        />

        <property
            name="interests"
            type="java.lang.String"
            update="true"
            insert="true"
            column="Interests"
            length="200"
        />

        <property
            name="language"
            type="java.lang.String"
            update="true"
            insert="true"
            column="language"
            length="50"
        />

        <property
            name="location"
            type="java.lang.String"
            update="true"
            insert="true"
            column="location"
            length="200"
        />

        <property
            name="occupation"
            type="java.lang.String"
            update="true"
            insert="true"
            column="occupation"
            length="200"
        />

        <property
            name="theme"
            type="java.lang.String"
            update="true"
            insert="true"
            column="theme"
            length="50"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-User.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

Code between sessionFactory.openSession() and session.close():
Code:
for (int i=0; i < assignedGroups.size(); i++)
{
        Long id = Long.valueOf((String)assignedGroups.get(i));
   Group newGroup = groupDAO.findById(id );
   user.getGroups().add(newGroup);
}
userDAO.saveOrUpdate(user);

Full stack trace of any exception that occurs:
None
Name and version of the database you are using:
MySQL 5.0.18-nt
The generated SQL (show_sql=true):
Code:
Hibernate: select group0_.id as id9_0_, group0_.adminGroup as adminGroup9_0_, group0_.description as descript3_9_0_, group0_.name as name9_0_ from groups group0_ where group0_.id=?
Hibernate: update users set avatar=?, email=?, password=?, rankId=?, signature=?, status=?, username=?, createdDate=?, modifiedDate=?, homepage=?, imAol=?, imIcq=?, imMsn=?, imYahoo=?, Interests=?, language=?, location=?, occupation=?, theme=? where id=?


For some reason it is not saving the associated group. Any help?


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.