Hibernate version:
3.0.1
Code between sessionFactory.openSession() and session.close():
Code:
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Property.forName("id"), "id");
projectionList.add(Property.forName("fileName"), "fileName");
projectionList.add(Property.forName("type"), "type");
Criteria criteria = getSession().createCriteria(Attachment.class)
.add(Restrictions.eq("individual", individual))
.add(Restrictions.eq("type", type));
criteria.addOrder(Order.asc("fileName"));
criteria.setProjection(projectionList);
criteria.setResultTransformer(new AliasToBeanResultTransformer(Attachment.class));
return criteria.list();
DescriptionI'm trying to use ProjectionList to avoid retrieving BLOB columns.
Code below produces something like this:
Code:
select this_.id as y0_, this_.file_name as y1_, this_.type as y2_
from attachments this_
where this_.individual_id = ?
and y2_ = ?;
Which gives nice ORA error:
Caused by: java.sql.SQLException: ORA-00904: "Y2_": invalid identifier.
When I comment :
Code:
// projectionList.add(Property.forName("type"), "type");
Then I get:
Code:
select this_.id as y0_, this_.file_name as y1_
from attachments this_
where this_.individual_id = ?
and this_.type = ?;
But I would like attachment.type to be retrieved.
Full stack trace of any exception that occurs:org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1525)
at org.hibernate.loader.Loader.list(Loader.java:1505)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:111)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1256)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:299)
[..]
Caused by: java.sql.SQLException: ORA-00904: "Y2_": invalid identifier
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:830)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2391)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2672)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:527)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:118)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1204)
at org.hibernate.loader.Loader.doQuery(Loader.java:368)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:208)
at org.hibernate.loader.Loader.doList(Loader.java:1522)
Name and version of the database you are using:Oracle9
Code: