I'm getting this odd error whenever I try to add a restriction to a property with a projection set on it. Hibernate tries to query using the property alias and not with its name. Properties without a projection works fine.
I had to use a sqlRestriction with the collumn name hardcoded on it as a workaround...
Does anyone know what could it be?
Hibernate version: 3.2.6ga
Code between sessionFactory.openSession() and session.close():
Code:
Criteria c = session.createCriteria(Customer.class).setProjection(
Projections.projectionList()
.add(Projections.property(Customer.PROP_ID), "id")
.add(Projections.property(Customer.PROP_NAME), "name")
)
.add(Restrictions.like(Customer.PROP_EMAIL, email))
.add(Restrictions.like(Customer.PROP_NAME, name));
The generated SQL (show_sql=true):
Code:
select
this_.ctm_id as y0_,
this_.ctm_name as y1_
from
customers this_
where
this_.ctm_mail like ?
and y1_ like ?
Full stack trace of any exception that occurs:
Code:
09:47:21,920 WARN JDBCExceptionReporter:77 - SQL Error: 1054, SQLState: 42S22
09:47:21,923 ERROR JDBCExceptionReporter:78 - Unknown column 'y1_' in 'where clause'
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2216)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at br.com.webtraffic.bidmanagement.dao.CustomerListDAOImpl.main(CustomerListDAOImpl.java:43)
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'y1_' in 'where clause'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1403)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
... 6 more
Name and version of the database you are using:MySQL 5