-->
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: special property "class" for ICriteria (easy credi
PostPosted: Wed Mar 12, 2008 9:55 am 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
There is a special property class that accesses the discriminator value of an instance in the case of polymorphic persistence.

In HQL: from Eg.Cat cat where cat.class = Eg.DomesticCat

In IQuery: "and product.class = :productType "

In ICriteria:?
This does not work --> cProduct.Add(Expression.Eq("class", true))


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 11:20 am 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
You example should work, if you know the discriminatorvalue in your code.

For instance if one of the subclasses of Foo har discriminator "BAR" the following code would work:

Code:
s.CreateCriteria(typeof(Foo)).Add(Expression.Eq("class", "BAR"))


Perhabs take a look at the generateded SQL to see what goes wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 12:12 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
I wish I could see the sql but I get an error on the ICriteria.List<T>() method "Can not reslove property: class of: ..."

However I just rebuilt and it seems to be working. Wierd - maybe the web application needed to be stopped and started for the SessionFactory to be reconstructed?

Out of interest do you know what would have caused the error above?

thx!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 12:23 pm 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
I have no idea, it sounds a little bit strange. My best guess would be that you spelled class in wrong casing.


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.