Hi,
I'm using Hibernate 3.3.0.SP1 and Derby 10.6.1.0
I try to build a Criteria via the Hibernate Criteria API. To narrow the resultset I use projections. I need to set the aliases the get the targetclass injected.
Code:
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.distinct(Projections.property(ATTR_ID)), ATTR_ID);
projectionList.add(Projections.property(ATTR_UMBRELLA_ID), ATTR_UMBRELLA_ID);
projectionList.add(Projections.property(ATTR_UMBRELLA_NAME), ATTR_UMBRELLA_NAME);
criteria.setProjection(projectionList);
criteria.setResultTransformer(Transformers.aliasToBean(UmbrellaFonds.class));
But unfortunately I get an error on the following created statement:
Code:
select distinct this_.UMBRELLA_FONDS_OID as y0_, this_.UMBRELLA_ID as y1_, this_.umbrellaname as y2_ from V_UMBRELLA_FONDS this_ where y1_=?
V_UMBRELLA_FONDS is a view and UMBRELLA_ID a part of the view. Not that complicated.
Code:
Caused by: ERROR 42X04: Column 'Y1_' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'Y1_' is not a column in the target table.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.ColumnReference.bindExpression(Unknown Source)
at org.apache.derby.impl.sql.compile.BinaryOperatorNode.bindExpression(Unknown Source)
at org.apache.derby.impl.sql.compile.BinaryComparisonOperatorNode.bindExpression(Unknown Source)
at org.apache.derby.impl.sql.compile.SelectNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
... 65 more
If I execute following statement by hand everything works fine.
Code:
select distinct this_.UMBRELLA_FONDS_OID as y0_, this_.UMBRELLA_ID as y1_, this_.umbrellaname as y2_ from V_UMBRELLA_FONDS this_ where this_.UMBRELLA_ID=?
Does Derby support restrictions on projection aliases generally or is simply my comprehension on how projections work wrong?
Thanks
z-boy