These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Aggregation using projection and criteria
PostPosted: Sun Oct 26, 2008 12:20 am 
Newbie

Joined: Sun Feb 18, 2007 1:05 pm
Posts: 16
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.