-->
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.  [ 3 posts ] 
Author Message
 Post subject: Please help me with JPQL
PostPosted: Tue Dec 04, 2007 11:25 pm 
Newbie

Joined: Tue Dec 04, 2007 7:07 pm
Posts: 3
I am quite proficient with SQL and Java but only starting with JPA/Hibernate.
I have a database table that stores some media clips. It might be a sound, image or both. The media itself is stored in BLOB column and each clip has a name and type (single character column). So, I created an abstract class Clip with following annotations:

Code:
@MappedSuperclass
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "CLIP_TYPE", discriminatorType = DiscriminatorType.CHAR)


My concrete classes have @DiscriminatorValue equal to "S" or "I" respectively, but they do not have type attribute.
Now I want to select all sound clips.
I know how to do it in native SQL but cannot figure out how to do it in JPQL.
Can someone please help me with that?
Thanks.


Top
 Profile  
 
 Post subject: Re: Please help me with JPQL
PostPosted: Tue Dec 04, 2007 11:36 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
gary002g wrote:
I know how to do it in native SQL but cannot figure out how to do it in JPQL.
Can someone please help me with that?
Thanks.


I don't know how exactly it is done in JPA but in HQL you query class attribute of your entity. Give it a try. It might be the same. Your query will look like

Code:
from foo where foo.class = 'X'



Farzad-


Top
 Profile  
 
 Post subject: I found the solution
PostPosted: Fri Dec 07, 2007 4:17 pm 
Newbie

Joined: Tue Dec 04, 2007 7:07 pm
Posts: 3
Apparently there is a Hibernate bug that does not add the value of discriminator column to the generated SQL.
I solved the problem by adding @Where annotation to the named query.
Just like in http://jroller.com/eyallupu/entry/getti ... en_mapping

It is not perfect but will do for a while.


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