-->
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.  [ 7 posts ] 
Author Message
 Post subject: using "class" property in hql where querying an an
PostPosted: Thu Feb 09, 2006 12:31 am 
Beginner
Beginner

Joined: Tue Dec 20, 2005 9:40 pm
Posts: 20
I'm trying to use the special property class in my hql query but it's saying

I'm getting the following error:

NHibernate.QueryException: could not resolve property:class of :eg.Domain.Track [select orderItem._ID from eg.Domain.Order.OrderItem as orderItem join orderItem.Product as track join track.Album as album where album.Artist._ID = 212 and orderItem.Product.class = 5]

the hql query is:

select orderItem._ID from OrderItem as orderItem
join orderItem.Product as track join track.Album as album where album.Artist._ID = 212 and track.class = 5

the mapping in OrderItem is:

<any name="Product"
meta-type="Int32"
id-type="Int32">
<meta-value class="eg.Domain.Track, eg.Domain" value="5"/>
<meta-value class="eg.Domain.Ringtone, eg.Domain" value="6"/>
<column name="item_type"/>
<column name="item_id"/>
</any>

can someone tell me what I've got wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 6:48 pm 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
in HQL the class clause should be used to test the equality with a class name. in your case should be "... track.class=Track"
I still don't understand what strategy did you use for mapping the inheritance hierarchy.

cheers,
radu


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 12:23 am 
Beginner
Beginner

Joined: Tue Dec 20, 2005 9:40 pm
Posts: 20
I used a Table per Concrete class Hierarchy.

However even if I use the class name (which I'm not sure is correct if I'm using meta-values), I still get the same error.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 12:35 am 
Beginner
Beginner

Joined: Tue Dec 20, 2005 9:40 pm
Posts: 20
Ahhh, I forgot to state polymorphism="implicit"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 1:16 am 
Beginner
Beginner

Joined: Tue Dec 20, 2005 9:40 pm
Posts: 20
And just in case anyone else has this problem...

1. polymorphic joins don't work if the Table per Class Hierarchy inheritance strategy is used, so you need to do an old fashioned join in the where clause
2. Since it's joining in the where clause, the orderItem.Product.class may not be necessary (I haven't tried it without it yet)
3. if you are using meta-values, the poster above was wrong, you do specify the value, not the class

so, the final query which worked is:

select orderItem from
OrderItem as orderItem,
Track as track,
Album as album,
where orderItem.Product.class = 5
and orderItem.Product.id = track.id
and track.Album.id = album.id
and album.Artist.id = 212


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 7:13 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
nick72 wrote:
And just in case anyone else has this problem...

1. polymorphic joins don't work if the Table per Class Hierarchy inheritance strategy is used, so you need to do an old fashioned join in the where clause


well, I'm using the table per class inheritance mapping strategy and polymorphic joins do work, but I'm using the joined-subclass element to map the subclass. can you give an example of a polymorphic query which doesn't work, please? - i'm eager to understand hibernate limitations.
Anyway I've noticed that the class clause produces buggy SQL whith this inheritance mapping strategy - i'm preparing to file a bug report on jira.

cheers,
radu


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 12:34 pm 
Beginner
Beginner

Joined: Tue Dec 20, 2005 9:40 pm
Posts: 20
sorry - i meant table per concrete class.


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