-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem with many-to-many mapping
PostPosted: Sun Dec 04, 2005 3:33 am 
Newbie

Joined: Sun Dec 04, 2005 2:55 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.5

Mapping documents:
Code:
    <class name="domain.Group" table="contact_group">
        ...

        <set
            name="contacts"
            table="group_contact_mapping"
            lazy="false"
            inverse="false"
            cascade="save-update"
            sort="unsorted">

            <key column="contact_group_id" />

            <many-to-many
                class="domain.Contact"
                column="contact_id"
                outer-join="auto"/>

        </set>
     </class>


Code between sessionFactory.openSession() and session.close():
Code:
    Contact phil = new Contact();
    phil.setFirstName("Phil");
    Group group1 = new Group("Group One");
    group1.getContacts().add(phil);
    session.save(group1);


Full stack trace of any exception that occurs:
None

Name and version of the database you are using:
HSQLDB 1.8.0

The generated SQL (show_sql=true):
Hibernate: insert into contact_group (name, id) values (?, null)
Hibernate: call identity()
Hibernate: insert into contact (first_name, id) values (?, null)
Hibernate: call identity()

Debug level Hibernate log excerpt:

There are no exceptions. The group and contact are saved to the database correctly. However the group_contact_mapping table is not updated with the many-to-many mapping. So when the group is retrieved, the contact is not retrieved. I must be doing something dumb, but I can't seem to track it down.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 7:39 pm 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
do you commit?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 3:10 am 
Newbie

Joined: Sun Dec 04, 2005 2:55 am
Posts: 2
Good point, I'm using Hibernate in coordination with Spring and have recently realized that Spring isn't commiting the transactions. Question for a different forum. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 4:03 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
maybe you want to take a look at the HibernateUtil in Caveat Emptor. With regards to hibernate 3.x the spring template looks a bit outdated imho.


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

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.