How do I select lets say 2 columns from a select statement instead of all columns?
When I specify the 2 columns in a Projection list, the iterator is giving me an object that is not Castable to the Entity class (Trade), and therefore, I am unable to invoke a getXXX for these columns.
Code:
Criteria criteria = session.createCriteria(Trade.class);
// SELECT specific columns.
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.property("order_num")).add(
Projections.property("del_source"));
iter = criteria.setProjection(projectionList).list().iterator();
// FIXME - How to handle the specific columms from the ResultSet?
while (iter.hasNext())
System.out.println(((Trade)iter.next()).getOrder_Num()); <--ERROR
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object;
at hibernate.client.TradeClient.main(TradeClient.java:91)