[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5074?page=c...
]
Strong Liu commented on HHH-5074:
---------------------------------
Florian,
Thanks for reporting this, it will better if you can attach a test case first :)
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira