-->
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: WrongClassException and Criteria API: different behaviours
PostPosted: Tue Mar 08, 2011 4:45 am 
Newbie

Joined: Wed Oct 31, 2007 5:15 am
Posts: 6
Hi all,

I am mixing table per class hierarchy and table per subclass strategies.
And I have different behaviours when trying to do a query.

Here is the inheritance tree:
Element <- Product <- CommercialProduct

I want to do a query on CommercialProduct.
When I'm using the Criteria API, with the following query:
Code:
getSession().createCriteria(CommercialProduct.class)

I got a WrongClassException saying that the object was alreay loaded as a Product.

When I am using an HQL query, it works fine:
Code:
getSession().createQuery(" from CommercialProduct ")


For the moment, it's only in a unit test. So I am not still dealing with objects already in session or other cases.
I tried to use discriminator force="true" with no changes.
By the way, when I look at SQL queries, I don't see the discriminated value in the where clause.

Can some one explain me why criteria uses the parent type to query?
Other question, the discriminated column should be used in the generated sql query, shouldn't it?

I am using Hibernate 3.3.2 with xml mapping (no annotations).
Thanks for your help.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.