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: Hibernate not retrieving correct discriminator subclasses
PostPosted: Mon Sep 13, 2004 4:40 am 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
My mapping file is as below:

<class name="MainClass" table="MAIN_CLASS">
<id name="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<discriminator column="class_type" type="string"/>

...

<property name="className" column="class_name" not-null="true" type="yes_no"/>
<property name="classType" column="class_type" not-null="true" type="yes_no"/>


<subclass name="CurrentSubClass" discriminator-value="CURRENT">
</subclass>

<subclass name="FutureSubClass" discriminator-value="FUTURE">
<property name="date" column="date" type="date"/>
</subclass>

</class>


I followed one of the examples somewhere but i cant seem to retrieve the correct subclass

i can save correctly in the sense that the discriminator value is set correctly but when i try to retrieve the specified subclasses i get both CurrentSubClass and FutureSubClass

Example, i mananged to store correctly 2x CurrentSubClass objects and 2xFutureSubClass objects but when i do a retrieval like this:

List subclassList = sess.createCriteria(SomeOtherClass.class)
.add( Expression.eq("id", new Long(1) ))
.setFetchMode("FutureSubClass", FetchMode.EAGER)
.list();

The number of results is 4 instead of just 2. i tried the same thing with hql and still get the same results so what gives? if you need more information please let me know. Thanks!!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 13, 2004 1:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Show the SomeOtherClass mapping

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 13, 2004 7:08 pm 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
<class name="MainClass" table="MAIN_CLASS">
<id name="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<discriminator column="class_type" type="string"/>

...

<many-to-one name="someOtherClass" class="reynolds.sms.hibernate.SomeOtherClass" column="some_other_class_id" not-null="true"/>

<property name="className" column="class_name" not-null="true" type="yes_no"/>
<property name="classType" column="class_type" not-null="true" type="yes_no"/>


<subclass name="CurrentSubClass" discriminator-value="CURRENT">
</subclass>

<subclass name="FutureSubClass" discriminator-value="FUTURE">
<property name="date" column="date" type="date"/>
</subclass>

</class>



//-------------------------SomeOtherClass
<class name="SomeOtherClass" table="SomeOtherClass">
<id name="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>

.....
<set name="currentSubClasses" cascade="all" lazy="true" inverse="true">
<key column="some_other_class_id"/>
<one-to-many class="CurrentSubClass"/>
</set>

<set name="futureSubClasses" cascade="all" lazy="true" inverse="true">
<key column="some_other_class_id"/>
<one-to-many class="FutureSubClass"/>
</set>

......

</class>

Thanks in advance Emmanual


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 04, 2004 1:48 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The returned subclasses are of the correct type.
You must distinct your SomeOtherClass(es) in your java code. they are returned several times per query.

_________________
Emmanuel


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.