-->
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: Problem with aliasing in where clause
PostPosted: Wed Dec 13, 2006 4:01 am 
Newbie

Joined: Mon Dec 04, 2006 12:39 pm
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1.3

Mapping documents:

Code between sessionFactory.openSession() and session.close():
Code:
   public List<OrderTimeRegInfo> findAllEntries(Employee worker, wtm.server.data.model.Order prodOrder) {
      Criteria criteria = getSession().createCriteria(getPersistentClass());
      criteria.add(Restrictions.eq(WTRegister.ORDER, prodOrder));
      
      criteria.setProjection(Projections.projectionList()
            .add(Projections.sum(WTRegister.TIMEUSED), "sumoftime")
            .add(Projections.groupProperty(WTRegister.PRODUCT), WTRegister.PRODUCT)
            .add(Projections.groupProperty(WTRegister.OPERATION), WTRegister.OPERATION)
            .add(Projections.property(WTRegister.ORDER),WTRegister.ORDER)
            .add(Projections.property(WTRegister.EMPLOYEE), WTRegister.EMPLOYEE)
      );
      criteria.setResultTransformer(new AliasToBeanResultTransformer(OrderTimeRegInfo.class));

      
      List<OrderTimeRegInfo> entries = (List<OrderTimeRegInfo>) criteria.list();


The generated SQL (show_sql=true):
Code:
Hibernate: select sum(this_.TimeUsed) as y0_, this_.Product as y1_, this_.Operation as y2_, this_.prodOrder as y3_, this_.Employee as y4_ from wtmworktimereg this_ where y3_=? group by this_.Product, this_.Operation order by this_.TimeStart desc
09:50:45,656 ERROR JDBCExceptionReporter:72 - Unknown column 'y3_' in 'where clause'




There is a problem in Hibernate - when you try to output the groupped column and there is also a restriction on this column, it uses the alias in 'where clause': so it uses y3_ instead of this_.prodOrder, causing an JDBC error.

Is it an official bug oor this situation can be avoided?[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 13, 2006 8:57 am 
Newbie

Joined: Mon Dec 04, 2006 12:39 pm
Posts: 5
http://opensource.atlassian.com/projects/hibernate/browse/HHH-817

Found the answer here. Yes, Hibernate has that behaviour which is not compatible with most RDBMS, incl. Oracle, MySQL and PostgreSQL.
The workaround is not to use aliases which are the same as properties.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 6:54 am 
Newbie

Joined: Tue Nov 28, 2006 9:34 am
Posts: 15
Location: Brasil
I'm having the same problem... Don't know about Rostyk_, but if i take the alias off or change the alias in any form, like the link with the answer suggests, my AliasToBeanResultTransformer stop working...

So.. Is this a problem without any solution? :(


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.