0

This is criteria which returns 6 columns.
ProjectionList projList = Projections.projectionList();

 projList.add(Projections.property("se.ticker"),"ticker"); projList.add(Projections.property("cl.firstName"),"firstName"); projList.add(Projections.property("cl.middleName"),"middleName"); projList.add(Projections.property("tr.client"),"client"); projList.add(Projections.sum("tr.cumulativeQty"),"cumulativeQty"); projList.add(Projections.sum("tr.cumulativeBalance"),"cumulativeBalance"); projList.add(Projections.groupProperty("tr.securityId")); Criteria criteria = createEntityCriteria(TransactionDetails.class, "tr") .createAlias("tr.client", "cl") .createAlias("tr.security", "se") .add(Restrictions.eq("cl.id", clientId)) .setProjection(projList); return (List<TransactionDetails>) criteria.list(); 

How to access column details(data with column). I have given the alias name but its of no use. Please Suggest me the way to access the column data.

2 Answers 2

0

You have two options

1 > You will get result as a list of array. you can iterate though them and get the columns.

List<Object[]> criteria = criteria.list(); for (Object[] result : results) { String ticker = (String)result[0]; String firstName = (String)result[1]; // other properties same way } 

2 > You can specify result transformer, hibernate will do the rest. You have to map columns in the projections with the VO object columns.

In you case you can have a VO object as below.

class TransactionDetailVO{ String ticker; String firstName; String lastName; //other properties. these properties map to the alias in projection projList.add(Projections.property("cl.firstName"),"firstName"). here it is `firstName`. } Criteria criteria = createEntityCriteria(TransactionDetails.class, "tr") .createAlias("tr.client", "cl") .createAlias("tr.security", "se") .add(Restrictions.eq("cl.id", clientId)) .setProjection(projList) .setResultTransformer(Transformers.aliasToBean(TransactionDetailVO.class)); List criteria = criteria.list(); for (Object result : results) { TransactionDetailVO transactionDetailVO = (TransactionDetailVO)result; // access the properties. } 

Here is an example.

Sign up to request clarification or add additional context in comments.

Comments

0

I used Iterator to get the data. Its working now.

transactionDetailsList = transactionDetailsDao.getClientHoldingsBySecurityIdClientId(securityId, clientId);

 List list = transactionDetailsList; Iterator it = list.iterator(); if (!it.hasNext()) { System.out.println("No any data!"); } else { while (it.hasNext()) { TransactionDetailsDto transactionDetailsDto = new TransactionDetailsDto(); Object[] row = (Object[]) it.next(); int count=0; for (int i = 0; i < row.length; i++) { switch (i) { case 0: transactionDetailsDto.setClientMasterId(Long.valueOf(row[i].toString())); Client client = clientDAO.load(transactionDetailsDto.getClientMasterId()); transactionDetailsDto.setClientDto(new ClientTransformer().transform(client)); break; } } 

}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.