-->
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.  [ 3 posts ] 
Author Message
 Post subject: Strange behavior: mixed up Collections in Subclasses
PostPosted: Thu Jun 30, 2005 11:58 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 2:23 pm
Posts: 21
Location: Pescara, italy
Hibernate version:
3.0.3
Mapping documents:
<?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="beans.Gebaeude" table="GEBAEUDE">

<id name="id" type="string" >
<column name="GEBAEUDE_ID" sql-type="int UNSIGNED"/>
<generator class="identity"/>
</id>
[...]
<joined-subclass name="beans.InProgressGebaeude" table="INPROGRESSGEBAEUDE">
<key column="GEBAEUDE_ID"/>

<property name="inProgressTyp" type="string">
<column name="INPROGRESSTYP" sql-type="varchar(25)"/>
</property>

<set name="buildRessource" lazy="true" inverse="true" cascade="all, delete-orphan">
<key column="GEBAEUDE_ID"/>
<one-to-many class="beans.Ressource"/>
</set>
[...]
</joined-subclass>

</class>

</hibernate-mapping>

<?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="beans.Ressource" table="RESSOURCE">

<id name="id" type="string" >
<column name="RESSOURCE_ID" sql-type="int UNSIGNED"/>
<generator class="identity"/>
</id>

<many-to-one name="gebaeude" class="beans.Gebaeude" column="GEBAEUDE_ID"/>

<many-to-one name="inProgressGebaeude" class="beans.InProgressGebaeude" column="GEBAEUDEINPROGRESS_ID"/>

</class>

</hibernate-mapping>

Name and version of the database you are using:
MySQL

Debug level Hibernate log excerpt:

Hi,

I have here two Collections that are mixed up.

I have a Class beans.Gebaeude and a subclass of Gebaeude named beans.InProgressGebaeude.
Gebaeude and InProgressGebaeude both define a SET of beans.Ressource.
One is named ressource, the other buildRessource.
beans.InProgressGebaeude therefor has two different SETs of that both contain instances of the class beans.Ressource.

These two sets are mixed up in my application.

Problem;
If I add a Ressource to the SET buildRessource it is persisted as a member of the other SET!
The strange thing is that if the other SET ressource does not exist in the DB persisting buildRessource works fine!

Is that a mapping error of mine?

Thanx
Kai
!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 01, 2005 2:14 pm 
Newbie

Joined: Mon Dec 27, 2004 4:19 pm
Posts: 1
I just encountered the same problem on my project.
I use 2.1.X on my project.
I have several instances where collections hierarchically in the same PersistentClass (that is collections that are in the class or any of its contained composites, recursively) that collect the same type have crosstalk.

We are currently investigating the problem. It seems odd to us that we have the problem at all. This suggests to us that there is some fairly obvious mapping file solution to it. We are considering using a discriminator column in the collected class and a where clause in the collection mappings.

My group would love to hear the right (or at least, a better) way of doing this, though.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 6:07 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 2:23 pm
Posts: 21
Location: Pescara, italy
Hi Derek,

during the weekend I have found a solution to the problem.
In fact my mapping was wrong. The subclass has to be mapped as follows:

<joined-subclass name="beans.InProgressGebaeude" table="INPROGRESSGEBAEUDE">
<key column="GEBAEUDE_ID"/>

<property name="inProgressTyp" type="string">
<column name="INPROGRESSTYP" sql-type="varchar(25)"/>
</property>

<set name="buildRessource" lazy="true" cascade="all, delete-orphan">
<key column="GEBAEUDEINPROGRESS_ID"/>
<one-to-many class="beans.Ressource"/>
</set>
</joined-subclass>

What you see underlined is the difference to my 1st mapping above. I have just finished testing and everything works fine.
I use hibernate 3.0.3

Gruss
Kai
!


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