-->
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: bi-directional links in many-to-many relationshit
PostPosted: Sat Nov 19, 2005 8:46 pm 
Newbie

Joined: Mon Sep 12, 2005 3:36 pm
Posts: 5
this is for hibernate3 using mysql

I have 2 objects; User and Group. users have many groups. everything is ok unit i try to make the link bi-directional, i get a LazyInitializationException (illegal access to loading collection)

here are my mapping files

User.hbm.xml
-----------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
<class name="com.bioinfocg.handset.model.User" table="user">
<id name="id" column="user_id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="username"/>
<property name="password"/>
<property name="fullName" column="full_name"/>
<property name="type"/>

<set name="groups" table="user_group">
<key column="user_id"/>
<many-to-many column="group_id" class="com.bioinfocg.handset.model.Group"/>
</set>

<set name="emails" table="user_email">
<key column="user_id"/>
<element type="string" column="email"/>
</set>

</class>
</hibernate-mapping>




Group.hbm.xml
-------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
<class name="com.bioinfocg.handset.model.Group" table="groups">
<id name="id" column="group_id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name"/>
<property name="active"/>

<set name="users" table="user_group" inverse="true">
<key column="group_id"/>
<many-to-many column="user_id" class="com.bioinfocg.handset.model.User"/>
</set>

</class>
</hibernate-mapping>



any help would be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 19, 2005 11:10 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
restep through your java - you will find that somewhere the session is being closed to early in in your clearly defined unit of work.


Top
 Profile  
 
 Post subject: using spring
PostPosted: Sun Nov 20, 2005 2:32 am 
Newbie

Joined: Mon Sep 12, 2005 3:36 pm
Posts: 5
i don't think that's it.


i've got a unit test testing a simple method which is basically just loading a User object, and checking the size of the groups set.

the setUp() contains

Session s = sf.openSession();
TransactionSynchronizationManager
.bindResource(sf, new SessionHolder(s));


the tearDown() contains

SessionHolder holder = (SessionHolder)
TransactionSynchronizationManager.getResource(sf);
Session s = holder.getSession();
s.flush();
TransactionSynchronizationManager.unbindResource(sf);
SessionFactoryUtils.releaseSession(s, sf);


i'm also using spring.


Marc


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 20, 2005 2:47 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
I don't do Spring ;)

Post the full TestCase, as well as the full stacktrace.


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.