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.  [ 1 post ] 
Author Message
 Post subject: hibernate criteria createAlias and groupBy
PostPosted: Tue Mar 18, 2008 10:11 am 
Newbie

Joined: Tue Mar 18, 2008 10:05 am
Posts: 1
hi

i am running into the following error when executing this criteria query:
Code:
      Criteria c = s.createCriteria(Copy.class).createAlias("rentals", "rent").createAlias("copyOf.actors", "act");
      
      if(customerId != null)
         c.add(Restrictions.eq("rent.customer.id", customerId));
      
      if(actorFirstName != null)
         c.add(Restrictions.ilike("act.firstName", actorFirstName));
      
      c.setProjection(Projections.groupProperty("id").as("copyId"));
      
      List<Copy> res = c.list();


it works fine when i comment out the following line

Code:
c.setProjection(Projections.groupProperty("id").as("copyId"));


Hibernate version:
Hibernate 3.2.6, Hibernate Annotations 3.3.1.GA

Full stack trace of any exception that occurs:
Quote:
[java] 18.03.2008 15:01:09 org.hibernate.util.JDBCExceptionReporter logExceptions
[java] WARNUNG: SQL Error: 0, SQLState: 42P01
[java] 18.03.2008 15:01:09 org.hibernate.util.JDBCExceptionReporter logExceptions
[java] SCHWERWIEGEND: ERROR: missing FROM-clause entry for table "act2_"
[java] Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
[java] at org.hibernate.loader.Loader.doList(Loader.java:2216)
[java] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
[java] at org.hibernate.loader.Loader.list(Loader.java:2099)
[java] at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
[java] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
[java] at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
[java] at tvs1.query.Queries.runCriteriaQueryC(Queries.java:131)
[java] at tvs1.Main.tvs03(Main.java:38)
[java] at tvs1.Main.main(Main.java:17)
[java] Caused by: org.postgresql.util.PSQLException: ERROR: missing FROM-clause entry for table "act2_"
[java] at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1548)
[java] at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1316)
[java] at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:191)
[java] at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
[java] at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:351)
[java] at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:255)
[java] at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
[java] at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
[java] at org.hibernate.loader.Loader.doQuery(Loader.java:674)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
[java] at org.hibernate.loader.Loader.doList(Loader.java:2213)
[java] ... 8 more

Name and version of the database you are using:
PostgreSQL 8.2

The generated SQL (show_sql=true):
Quote:
Hibernate: select this_.id as y0_ from Copy this_ inner join Rental rent1_ on this_.id=rent1_.COPY_ID where rent1_.CUSTOMER_ID=? and act2_.firstName ilike ? group by this_.id


thanks in advance for any hints...

kr
Stefan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.