-->
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.  [ 2 posts ] 
Author Message
 Post subject: help, exception: illegal attempt to associate a..with 2...
PostPosted: Sun Jun 27, 2004 7:32 am 
Newbie

Joined: Sun Jun 27, 2004 7:21 am
Posts: 2
hibernate version: 2.0.3

hi, i've got the following exception when i try to save an object:

[java] net.sf.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
[java] at net.sf.hibernate.collection.PersistentCollection.setSession(PersistentCollection.java:188)
[java] at net.sf.hibernate.impl.SessionImpl.removeCollectionsFor(SessionImpl.java:1076)
[java] at net.sf.hibernate.impl.SessionImpl.removeCollectionsFor(SessionImpl.java:1047)
[java] at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1291)
[java] at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1206)
[java] at com.pcxion.genesis.product.Catalogue.save(Catalogue.java:50)
[java] at com.pcxion.genesis.test.Test.main(Test.java:45)

mapping file:
*** Catalogue.hbm.xml ***
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="com.pcxion.genesis.product.Catalogue" table="catalogue">

<id name="id" column="id" type="long" unsaved-value="0">
<generator class="hilo">
<param name="table">hilo_tbl</param>
<param name="column">next</param>
</generator>
</id>
<property name="name" type="string" not-null="true"/>
<property name="description" type="string" not-null="false"/>
<property name="flgDefault" type="boolean" not-null="true"/>
<set name="categories" cascade="all">
<key column="catalogue_id"/>
<!--index column="seq"/--> <!-- sequence of each tx item-->
<one-to-many class="com.pcxion.genesis.product.Category"/>
</set>
</class>

</hibernate-mapping>

*** Category.hbm.xml ***
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="com.pcxion.genesis.product.Category" table="category">

<id name="id" column="id" type="long" unsaved-value="0">
<generator class="hilo">
<param name="table">hilo_tbl</param>
<param name="column">next</param>
</generator>
</id>
<property name="name" type="string" not-null="true"/>
<property name="description" type="string" not-null="false"/>

<!-- many children to parent -->
<many-to-one name="parent" column="parent_id"/>

<!-- parent has many children -->
<set name="subCategories" inverse="true" cascade="all">
<key column="parent_id"/>
<one-to-many class="com.pcxion.genesis.product.Category"/>
</set>

<set name="products" table="category_product">
<key>
<column name="cat_id" not-null="true"/>
</key>
<many-to-many class="com.pcxion.genesis.product.Product">
<column name="p_id" not-null="true"/>
</many-to-many>
</set>

</class>

</hibernate-mapping>

*** Product.hbm.xml ***
...
<set name="groupings" table="category_product" inverse="true" lazy="false">
<key>
<column name="p_id" not-null="true"/>
</key>
<many-to-many class="com.pcxion.genesis.product.Category">
<column name="cat_id" not-null="true"/>
</many-to-many>
</set>
...


The code that causes the exception:
Product p = new Product();
p.setProductCode("0110");
p.setShortDesc("product test");
p.setLongDesc("long desc");
p.setCtnCost(10.00);
p.setRrp(0.00);
p.setCtnQty(1);
p.setOrderCode("xxx");
p.setGstCode(Product.GST_10);
p.setMinOrdQty(1);

Catalogue c = (new Catalogue()).findById(917505); // Report groups
Category cat = new Category();
cat.setName("category with products");
cat.setDescription("cat a description");
cat.setParent(null);
cat.addProduct(p);
p.addGrouping(cat);
c.addCategory(cat);

try{
//cat.save();
c.save(); // <---- *** exception here
p.save();
}catch(Exception e){
e.printStackTrace();
}
...

Catalogue.save() method:

...
try{
Session session = Database.getInstance().newSession();
session.saveOrUpdate(this); // <---- exception here
session.flush();
session.close();
}catch(Exception e){
e.printStackTrace();
throw new Exception(e);
}
...


I don't have two open sessions at the same time, can somebody help me please


Top
 Profile  
 
 Post subject: SORRY - problem solved
PostPosted: Sun Jun 27, 2004 8:40 am 
Newbie

Joined: Sun Jun 27, 2004 7:21 am
Posts: 2
SORRY guys, i forgot to close the session in one of my Catalogue.findXXX methods.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.