[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5074) Criteria query using AliasToBeanResultTransformer fails with 3.5-Final

dnalos (JIRA) noreply at atlassian.com
Tue Apr 6 09:44:02 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=36170#action_36170 ] 

dnalos commented on HHH-5074:
-----------------------------

I have an error after update to hibernate 3.5.
I get this Error: Column '_version' in field list is ambiguous
I have post the SQL Query from both version.

Before (Hibernate 3.2):
select
userroleim0_._dbid as column1_6_,
userroleim0_.idHigh as idHigh6_,
userroleim0_.idLow as idLow6_,
userroleim0_._version as column4_6_,
userroleim0_.defaultPartition_id as defaultP6_6_,
userroleim0_._gesperrt as column5_6_,
userroleim0_.user_id as user7_6_
from
resys_userrole userroleim0_, comm_user userimpl1_
where userroleim0_.user_id=userimpl1_._dbid and userimpl1_._loginname='admin';

After (Hibernate 3.5):
select
userroleim0_._dbid as column1_6_,
userroleim0_.idHigh as idHigh6_,
userroleim0_.idLow as idLow6_,
_version as column4_6_,
userroleim0_.defaultPartition_id as defaultP6_6_,
_gesperrt as column5_6_,
userroleim0_.user_id as user7_6_
from
resys_userrole userroleim0_ cross join comm_user userimpl1_
where userroleim0_.user_id=userimpl1_._dbid and _loginname='admin';

> Criteria query using AliasToBeanResultTransformer fails with 3.5-Final
> ----------------------------------------------------------------------
>
>                 Key: HHH-5074
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5074
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core, query-criteria, query-sql
>    Affects Versions: 3.5.0-Final
>         Environment: Hibernate 3.5-Final,
> Database: MySQL 5.1.45 GA,
> JDBC: mysql-connector-java-5.1.12
>            Reporter: Florian Grote
>
> I use the following Criteria query to receive the top ten users for an attribute "scoreSum". Attribute "statistic" is an embedded child (@Embeddable) of "User" entity.
> The result is written directly into a value object using AliasToBeanResultTransformer.
> {code:title=Criteria query|borderStyle=solid}
> @SuppressWarnings("unchecked")
> @Override
> public List<TopUserVO> getTopUsersAsVO(int max) {
>   return getCurrentSession().createCriteria(User.class)
>     .setProjection(Projections.projectionList()
>       .add( Projections.property("username"), "username" )
>       .add( Projections.property("statistic.scoreSum"), "scores" )
>   )
>   .addOrder(Property.forName("statistic.scoreSum").desc())
>   .setMaxResults(max)
>   .setResultTransformer( new AliasToBeanResultTransformer(TopUserVO.class) )
>   .list();
> }
> {code}
> Until inclusive Hibernate version 3.5-CR2 this runs fine and results in the valid (My-)SQL query:
> {quote}
> select 
> this_.USERNAME as y0_, 
> this_.SCORE_SUM as y1_ 
> from USER this_ 
> order by this_.SCORE_SUM desc limit ?
> {quote} 
> After upgrading to Hibernate version 3.5-final the same query fails because SQL query is not created correctly anymore. Corrupted SQL:
> {quote} 
> select 
> {color:red}*y0_ as y0_,*{color} 
> this_.SCORE_SUM as y1_
> from USER this_
> order by this_.SCORE_SUM desc
> {quote} 
> Problem is that "y0_" is used twice, instead of using it only as alias: "this_.USERNAME as y0_".
> Here is the relevant part of the root stacktrace:
> {code:title=Root Exception}
> com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'y0_' in 'field list'
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
> 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
> 	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
> 	at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
> 	at com.mysql.jdbc.Util.getInstance(Util.java:384)
> 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
> 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3562)
> 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3494)
> 	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1960)
> 	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114)
> 	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2696)
> 	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2105)
> 	at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2264)
> 	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:342)
> 	at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
> 	at org.hibernate.loader.Loader.getResultSet(Loader.java:1849)
> 	at org.hibernate.loader.Loader.doQuery(Loader.java:718)
> 	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
> 	at org.hibernate.loader.Loader.doList(Loader.java:2294)
> 	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
> 	at org.hibernate.loader.Loader.list(Loader.java:2167)
> 	at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
> 	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1706)
> 	at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
> 	at xyz.dao.UserDaoImpl.getTopUsersAsVO(UserDaoImpl.java:95)
> {code}
> I will try to research the new Hibernate code and the difference to the old one and try to provide a patch.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list