-->
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: Illegal attempt to associate a collection with two open sess
PostPosted: Mon Nov 12, 2007 10:02 am 
Newbie

Joined: Mon Nov 12, 2007 8:04 am
Posts: 1
Dear Friends,
I'm from Argentina and I'm a beginer english student, I'll try to explain my problem with hibernate, sorry for my english!! =P

Well, I have one abstract class called "Region"a and this class has three subclass "Country" , "State" and "Location".
This classes has de same basic properties (id, name) inherit from "Region" , but Country have a Collection for their "States"and State have a Collections for their "Locations" and one more thing every State knows his Country and every Location knows his State.
The structure is similar to this.

Class Region {
private int id;
private String name;
.
.
.
}

Class Country extends Region {
private Set states;
.
.
}

Class State extends Region {
private Set locations;
private Country country;
.
.
}

Class Location extends Region {
private State state;
.
.
}

I want to store my 3 classes in only one table in this case I created this table in my database.

CREATE TABLE regions (
idregion INT NOT NULL Autoincrement,
name VARCHAR(60) NOT NULL,
dtype VARCHAR(31) NOT NULL,
idfather int NULL,
)

dtype is for discriminator , and idfather is the FK to join one Country with their States or one State with their Locations.

I created this map file for hibernate:

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

<hibernate-mapping>
<class name="Region" table="REGIONS">

<id name="id" type="int" column="idregion" unsaved-value="-1">
<generator class="identity"/>
</id>

<discriminator column="dtype" type="string"/>
<property name="name" type="string" not-null="true"/>

<subclass name="Country" discriminator-value="COUNTRY">
<set name="states" inverse="true" lazy="false" cascade="ALL">
<key column="idfather"/>
<one-to-many class="State"/>
</set>
</subclass>

<subclass name="State" discriminator-value="STATE">
<many-to-one name="country" class="Country" column="idpadre"/>
<set name="locations" inverse="true" lazy="false" cascade="ALL">
<key column="idpadre"/>
<one-to-many class="Location"/>
</set>
</subclass>

<subclass name="Location" discriminator-value="LOCATION">
<many-to-one name="state" class="State" column="idpadre"/>
</subclass>

</class>
</hibernate-mapping>


Well my problem appeared when I tried to loaded one Country from the Database, changed the name, and then tried to saved the Country.
In this case Netbeans Show me the next error message "Illegal attempt to associate a collection with two open sessions".
I don't know how I can solve this problem, if anybody know it, pleaseee tell me.
Thanks a lot to everybody.
Greetings

Martin


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.