Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1
Hi,
I am trying to get the aggregate sum of al transactions grouped by account heads.My DayBook class attributes are is as follows
Code:
private int txnId;
private AccountHead accountHead=new AccountHead();
private String type;
private float credit;
private float debit;
private Date txnDate;
private int orgId;
My Daybook mapping file is given below
<hibernate-mapping auto-import="true" default-lazy="false">
<class name="com.scientia.dms.commons.vo.DioceseDaybook" table="v_fin_diocese_daybook" mutable="false" >
<id name="txnId" type="int">
<column name="TXN_ID" />
</id>
<many-to-one name="accountHead" class="com.scientia.dms.commons.vo.AccountHead" fetch="join">
<column name="ACCOUNT_HEAD_ID" />
</many-to-one>
<property name="type" type="string">
<column name="TXN_TYPE" length="2" />
</property>
<property name="credit" type="float">
<column name="credit" precision="10" />
</property>
<property name="debit" type="float">
<column name="debit" precision="10" />
</property>
<property name="txnDate" type="date">
<column name="TXN_DATE" length="10" />
</property>
<property name="orgId" type="int">
<column name="org_id" />
</property>
</class>
</hibernate-mapping>
And my DAO have the following method
Code:
public void test(){
try{
Session session = sessionFactory.getCurrentSession();
Criteria orgCrit = session.createCriteria(DioceseDaybook.class);
orgCrit.setProjection(Projections.projectionList()
.add(Projections.sum("credit"))
.add(Projections.sum("debit"))
.add(Projections.groupProperty("accountHead.accountHead")) // Line 1
);
List<Daybook> list=orgCrit.list();
Iterator itr=list.iterator();
while(itr.hasNext()){
Object[] row=(Object[])itr.next();
for(int i=0;i<row.length;i++){
System.out.println("Value>>>>>>>>"+row[i].toString());
//System.out.println("Credit>>>>>>>>"+row[i].toString());
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
Now the issue is , when I execute the function I am getting the following exception
Code:
could not resolve property: accountHead.accountHead of: com.scientia.dms.commons.vo.DioceseDaybook
If i replace the line marked as line 1 with
Code:
add(Projections.groupProperty("accountHead.accountHeadId")
This works fine
My AccountHead calss attributes are as below
Code:
private int accountHeadId;
private String accountHead;
private String desc;
private AccountSchedule schedule= new AccountSchedule();
private String org_type;
Can anyboy suggest me a solution.Am I doing rigt bu using the criteria and projection?
Thanks in Adv.
Shaiju
Read this:
http://hibernate.org/42.html