-->
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: Problem with HQL
PostPosted: Thu Dec 06, 2007 9:34 am 
Newbie

Joined: Thu Dec 06, 2007 6:43 am
Posts: 3
Hibernate version: 3

Code between sessionFactory.openSession() and session.close():
Query query = session.createQuery("
from MyObject where "+
"field1||' '||field2 in ("+
"select field1||' '||field2 from MyObject group by field1||' '||field2 having count(field1||' '||field2) > 1)");
list = query.list() ;

Full stack trace of any exception that occurs:
org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '||' near line 1, column 207 [from fr.test.data.MyObject where field1||' '||field2 in (select field1||' '||field2 from fr.test.data.MyObject group by field1||' '||field2 having count(field1||' '||field2) > 1)]
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)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at fr.infodb.toolsbox.core.data.HibernateDataHelper.retrieveHQL(HibernateDataHelper.java:203)
at fr.infodb.webasma.data.impl.data.AssmatDataService.retrieveHQL(AssmatDataService.java:96)
at fr.infodb.webasma.business.impl.data.AssmatBusinessService.retrieveWithHQL(AssmatBusinessService.java:124)
at org.apache.jsp.admin.retrieveAllUnknowPoint_jsp._jspService(retrieveAllUnknowPoint_jsp.java:102)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)

Name and version of the database you are using: postgres 8

So know with this i think that all information are in the message.
Could you tell me why the concat (||) is not permitted in having count instruction ?

Thanks in advance
Regards,

Denez


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 06, 2007 12:20 pm 
Newbie

Joined: Thu Dec 06, 2007 6:43 am
Posts: 3
Nobody have understood my problem, or (i don't hope) is there is no answer ?
Thanks in advance.
Regards,

Denez


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 06, 2007 12:39 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
denezImhotep wrote:
Nobody have understood my problem, or (i don't hope) is there is no answer ?
Thanks in advance.
Regards,

Denez


I do believe it doesn't recognize it at all. What are you trying to do? What does your query have to do?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 06, 2007 12:57 pm 
Newbie

Joined: Thu Dec 06, 2007 6:43 am
Posts: 3
i have a table (MyObject) that contains two fields (field1 and field2).
I would like to get a list of information of the couple fields who is in the table more than once.

--------------
| MyObject |
--------------
| field1 |
| field2 |
--------------

Rows
----------------------
| field1 | field2 |
----------------------
| 1 | 1 |
----------------------
| 1 | 0 |
----------------------
| 0 | 1 |
----------------------
| 1 | 1 |
----------------------
| 0 | 0 |
----------------------
| 0 | 1 |
----------------------

With the request i should have this list :
----------------------
| field1 | field2 |
----------------------
| 1 | 1 |
----------------------
| 0 | 1 |
----------------------

Witch represent the couple of fields witch are more than one in the table.
I hope that is more clear.

Regards,

Denez


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 06, 2007 1:11 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
denezImhotep wrote:
Witch represent the couple of fields witch are more than one in the table.
I hope that is more clear.

Regards,

Denez



Do you only need the values or instances of MyObject. If you only need the values then you would do a simple group by:

Code:
select mo.field1, mo.field2 from MyObject mo group by mo.field1, mo.field2 having count(mo.field1) > 1



Farzad-


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.