-->
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: Traversing Multiple Relationships doesnt work with hibernate
PostPosted: Thu Aug 07, 2008 12:12 pm 
Newbie

Joined: Thu Aug 07, 2008 12:03 pm
Posts: 16
In the Sun EJB-QLl documentation I can see that convinients queries like this one can be performed:

SELECT DISTINCT p
FROM Player p, IN (p.teams) t
WHERE t.league = :league

Data retrieved: The players that belong to the specified league.

(( here: http://java.sun.com/javaee/5/docs/tutor ... bnbtl.html ))

That's great. A very cozy way to traversing multiple relationships.

Unfortunately this named query doesn't work with hibernate:


Code:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: u near line 1, column 111 [SELECT DISTINCT g FROM com.cinerent.starticketmediacenter.server.model.impl.Group g, IN(g.usersSubscribed) AS u WHERE u.username = :username]
   at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
   at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
   at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
   at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:258)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
...


Am I doing something wrong? or is not possible?
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 07, 2008 1:39 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I am not familiar with Sun EJB-QLl, but from your description of what the result should be I think it is something that can be done with a JOIN in HQL. Try something like:

Code:
SELECT DISTINCT p
FROM Player p JOIN p.teams t
WHERE t.league = :league


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 08, 2008 3:08 am 
Newbie

Joined: Thu Aug 07, 2008 12:03 pm
Posts: 16
Thank's for you answer. Very appreciated.

So, it seems I've been confused about named queries. I don't really know what language I have to use there. In theory, that's the JPA layer and I thought I had to use EJB-QL (after all, the @NamedQuery comes from the package javax.persistence which is JPA).

I would like to use standards JPA QL queries, just in case we change the ORM layer. that's why i was trying to stick to JPA.


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.