-->
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: many-to-many relation for subclass -
PostPosted: Tue Mar 16, 2004 9:08 am 
Newbie

Joined: Thu Nov 20, 2003 9:26 pm
Posts: 2
Location: Moscow,Russian Federation
Hello all

Excuse my english .
Could you help me with this issue?


Hibernate version 2.0.3

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="smi.SMIObject" table="object" discriminator-value="O">

<id name="id" column="id">
<column name="id" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<discriminator column="object_type_id" type="character" />
<property name="name" />


<many-to-one name="objectType" cascade="delete" column="object_type_id" class="smi.ObjectType" not-null="true" insert="false" update="false"/>

<set name="entities" inverse="true" cascade="all-delete-orphan">
<key column="object_id"/>
<one-to-many class="smi.EntityValue"/>
</set>
<set name="groups" table="obj_group_lnk">
<key column="object_id"/>
<many-to-many column="groups_id" class="smi.Group"/>
</set>
<subclass name="smi.Article" discriminator-value="2">
<set name="persons" table="obj_lnk">
<key column="object_id"/>
<many-to-many column="object_id2" class="smi.Person"/>
</set >
<set name="authors" table="obj_lnk">
<key column="object_id"/>
<many-to-many column="object_id2" class="smi.Author"/>
</set>
</subclass>
<subclass name="smi.Person" discriminator-value="3">
<set name="articles" table="obj_lnk">
<key column="object_id2"/>
<many-to-many column="object_id" class="smi.Article"/>
</set>
</subclass >
<subclass name="smi.Author" discriminator-value="6">
<set name="articles" table="obj_lnk">
<key column="object_id2"/>
<many-to-many column="object_id" class="smi.Article"/>
</set>
</subclass>
</class>
</hibernate-mapping>

-------
content of "object" table

id name object_type_id
402890effb4fc66b00fb4fc6ac780001 | Max | 6 |
402890effb53c02700fb53c043e30001 | test art | 2 |

content of obj_lnk table

object_id object_id2
402890effb4fc66b00fb4fc6ac780001 | 02890effb53c02700fb53c043e30001


---------------
next code throw exception

Article article = new Article();
Session sess= SMISessionFactory.getSession();
Transaction tx = sess.beginTransaction();
String id = (String)sess.save(article);
tx.commit();
sess.refresh(article);





net.sf.hibernate.WrongClassException: Object with id: 402890effb4fc66b00fb4fc6ac780001 was not of the specified subclass: smi.Author (loaded object was of wrong class)
at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:300)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:278)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:159)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602)
at net.sf.hibernate.loader.CollectionLoader.initialize(CollectionLoader.java:82)
at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897)
at net.sf.hibernate.collection.PersistentCollection.getInitialValue(PersistentCollection.java:128)
at net.sf.hibernate.type.PersistentCollectionType.getCollection(PersistentCollectionType.java:74)
at net.sf.hibernate.type.PersistentCollectionType.resolveIdentifier(PersistentCollectionType.java:177)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1959)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602)
at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102)
at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897)
at net.sf.hibernate.collection.PersistentCollection.getInitialValue(PersistentCollection.java:128)
at net.sf.hibernate.type.PersistentCollectionType.getCollection(PersistentCollectionType.java:74)
at net.sf.hibernate.type.PersistentCollectionType.resolveIdentifier(PersistentCollectionType.java:177)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1959)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:587)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396)
at net.sf.hibernate.impl.SessionImpl.refresh(SessionImpl.java:1932)
at net.sf.hibernate.impl.SessionImpl.refresh(SessionImpl.java:1902)
at smi.admin.AddArtcileForm.init(AddArtcileForm.java:69)
at smi.admin.AddArtcileForm.<init>(AddArtcileForm.java:45)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 9:10 am 
Newbie

Joined: Thu Nov 20, 2003 9:26 pm
Posts: 2
Location: Moscow,Russian Federation
But if i comment string about Person class in xml file - all work correctly. =(


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 10:34 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Quote:
<set name="persons" table="obj_lnk">
<key column="object_id"/>
<many-to-many column="object_id2" class="smi.Person"/>
</set >
<set name="authors" table="obj_lnk">
<key column="object_id"/>
<many-to-many column="object_id2" class="smi.Author"/>
</set>

Article is linked with person and Author using the same relation table and same object_id2, This cannot work. Hibernate will try to load a Person with an Author id.

_________________
Emmanuel


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.