-->
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.  [ 5 posts ] 
Author Message
 Post subject: session.load(subclass.class, id) problem
PostPosted: Tue Sep 14, 2004 9:03 am 
Newbie

Joined: Tue Sep 14, 2004 8:40 am
Posts: 4
Hibernate version:
2.1.2
Name and version of the database you are using:
Oracle 8i
Mapping documents:
<hibernate-mapping>
<class
name="Complement"
table="COMPLEMENT"
>
<id
name="id"
type="long"
column="ID">
</id>
<discriminator column="code" type="java.lang.String" />
<subclass
name="ComplementSubClass"
discriminator-value="SUBCLASS"
</subclass>
<subclass
name="OtherSubClass"
discriminator-value="OTHER_SUBCLASS"
</subclass>
</class>

in database table COMPLEMENT :
ID = 1 Code = 'OTHER_SUBCLASS'
ID = 2 Code = 'SUBCLASS'


Code between sessionFactory.openSession() and session.close():
session.load(ComplementSubClass.class,1)

The generated SQL (show_sql=true):
missing where code='SUBCLASS'
got this where clause only when i call a hql query from my .hbm file

Problem :

Hibernate Session.load(ComplementSubClass.class, 1) return me a ComplementSublass but ID=1 of table COMPLEMENT is OtherSubClass not ComplementSubClass ...

anyone got an idea ?

thanks
Franck


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 14, 2004 6:39 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
You have been explictly asking to return a SubClass in your 'load()' call.

Try...

Code:
session.load(Complement.class,1)

... and you will probably get what you want.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 4:41 am 
Newbie

Joined: Tue Sep 14, 2004 8:40 am
Posts: 4
Thanks for your reply

in fact, i'm asking ComplementSubClass with id 1
i 'am expecting a 'not found exception' cause id 1 is not a ComplementSubclass record.

id 1 = OtherSubclass

that's why i dont understand.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 4:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is an application error (ie. yours). Use a query if you don't know what class the id represents.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2004 9:52 am 
Newbie

Joined: Tue Sep 14, 2004 8:40 am
Posts: 4
after few attempts, this is the only way i found to get it :



Object obj = session.load(Complement.class, 1)
// (Complement.class is the superClass)

ComplementSubclass subClassReturned = null;

if ( obj instanceof ComplementSubclass ) {
subClassReturnedreturned = (ComplementSubclass) obj;
}

return subClassReturned;


that work, but i really dunno if it's the right way to do it.


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