-->
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.  [ 5 posts ] 
Author Message
 Post subject: Simple (or not so simple) hql Problem
PostPosted: Mon Nov 10, 2003 12:23 pm 
Newbie

Joined: Mon Sep 29, 2003 12:21 pm
Posts: 4
Hi,

I have read all the Manuels and tried to find a Solution in the Forum but I wasn't able to. So I hope this is the right place to ask the following question.

I'm developing a kind of an issue tracking system with hibernate. I have Issues (so called Ivents) which have Details. Every single Detail Entity has a bunch of detail values. I've mapped them as an Map-Collection (Key-Value paradigm). Unfortunatly I need an non lazy relation to the creator of such an detail (UserJDO) but everything is fine till here.

Now I need some very fast query to implement statistics. I need only a few fields from Ivent and Detail which isn't a problem at all. But I also need the Value of one special indice. For Example :

"select ivent.id, detail from Ivent as ivent join ivent.details as detail" Is fine but it will load far to much data (all detail_values and the creator (User).

What I need is something like :
"Select ivent.id, detail.name, detail.detailValues["cost"], detail.detailValues["weakness"] ..... " where [""] means "Get the Value for the key xyz.

I wasn't able to find any way to do this with Hibernate right now. Am I blind or is hibernate not designed for such a query ?

I hope you can understand my problem.

kind Regards, Stefan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2003 12:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The [] construct is not supported in the select clause (yet). It only works in the where clause. (Its a real PIA to parse and translate to SQL, is the problem.)

However, you can do what you want to do using the index() function in Hibernate 2.1. eg:

select foo, bar from Foo foo foo.bars bar where index(bar) = "x"


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2003 12:54 pm 
Newbie

Joined: Mon Sep 29, 2003 12:21 pm
Posts: 4
Hmm I'm sorry but this didn't solved my Problem.

I got the following Exception
Code:
net.sf.hibernate.QueryException: collection of values in from clause: detail0_.detailValues.elements [select detail,bar from de.ivent.jdo.Detail detail, detail.detailValues bar   where index(bar)= :dvname]
   at net.sf.hibernate.hql.PathExpressionParser.addFromCollection(PathExpressionParser.java:420)
   at net.sf.hibernate.hql.FromParser.token(FromParser.java:195)
   at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
   at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:120)
   at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
   at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:146)
   at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:133)
   at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:352)
   at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:330)
   at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1368)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1332)
   at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:76)
   at Test.main(Test.java:61)


If I try to use this HQL :
Code:
Query q = s.createQuery("select detail,bar from de.ivent.jdo.Detail detail, detail.detailValues bar where index(bar) = :dvname");
q.setParameter(":dvname","praemierung");


(The dvParameter is my key)

Any clue ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2003 1:18 pm 
Newbie

Joined: Mon Sep 29, 2003 12:21 pm
Posts: 4
OK, my error is that I use Hibernate 2.0 for productions. Any solution of this in 2.0 ?

kind Regards Stefan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2003 7:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, 2.1 only.


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