Reputation: 1126
I have the following setting:
A CallRegistry bean that has TrunkBean in it and TrunkBean has Operator bean.
In my criteria Im adding:
criteria.createAlias("callRegistry.trunk", "trunk");
criteria.createAlias("trunk.operator", "op");
I need to use GSON on the resulting list to populate a datatable but the problem is the resulting list always return the TrunkBean, OperatorBean and CallRegistry inside a Object.
. resultadoQuery is the queryResult after list() troncoBean is trunk, operadora is operator, rlBean is callRegistry
What can I do to maybe filter this and get only the CallRegistry bean to come in the result? Is this even possible? Is there other alternatives to this problem?
This is also being done (and commenting these two lines solves the problem):
total = (Number) criteria.setProjection(Projections.rowCount()).uniqueResult();
criteria.setProjection(null)
Why is this breaking?
Upvotes: 0
Views: 62
Reputation: 492
When you called the criteria.setProjection(null);
the ResultTransformer
was configured with the PassThroughResultTransformer
and this transformer just returns an array
with the aliases you declared.
You only set the projection of a criteria, if you want to specify that the query results will be a projection (scalar in nature). The individual components contained within the given projection determines the overall "shape" of the query result.
Example, in the first line you commented total = (Number) criteria.setProjection(Projections.rowCount()).uniqueResult();
, the result would be the number of rows your query would return, just like SELECT count(*)
.
Details on how to use projections: http://docs.jboss.org/hibernate/orm/4.0/manual/en-US/html/querycriteria.html#querycriteria-projection
Upvotes: 1