-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem with composite key search
PostPosted: Thu Jan 25, 2007 3:27 am 
Newbie

Joined: Thu Jan 25, 2007 3:24 am
Posts: 6
Hi,

I have a table PEN_DCRG_AMOUNT_DTL.

The hbm file is like:
<hibernate-mapping>
<class name="com.ctmis.pension.hibernate.PenDcrgAmountDtl" table="PEN_DCRG_AMOUNT_DTL" schema="EMPLOYEE">
<composite-id name="id" class="com.ctmis.pension.hibernate.PenDcrgAmountDtlId">
<key-property name="ppoCode" type="java.lang.String">
<column name="PPO_CODE" length="20" />
</key-property>
<key-property name="slNo" type="java.lang.Long">
<column name="SL_NO" precision="2" scale="0" />
</key-property>
<key-property name="treasuryCode" type="java.lang.String">
<column name="TREASURY_CODE" length="3" />
</key-property>
</composite-id>
<property name="dcrgAmount" type="java.lang.Double">
<column name="DCRG_AMOUNT" precision="8" />
</property>
<property name="gpoNo" type="java.lang.String">
<column name="GPO_NO" length="20" />
</property>
<property name="dated" type="java.util.Date">
<column name="DATED" length="7" />
</property>
<property name="status" type="java.lang.String">
<column name="STATUS" length="1" />
</property>
<property name="createUid" type="java.lang.String">
<column name="CREATE_UID" length="20" />
</property>
<property name="createDate" type="java.util.Date">
<column name="CREATE_DATE" length="7" />
</property>
<property name="modifiedUid" type="java.lang.String">
<column name="MODIFIED_UID" length="20" />
</property>
<property name="modifiedDate" type="java.util.Date">
<column name="MODIFIED_DATE" length="7" />
</property>
<property name="tokenNo" type="java.lang.String">
<column name="TOKEN_NO" length="10" />
</property>
<property name="tokenDate" type="java.util.Date">
<column name="TOKEN_DATE" length="7" />
</property>
<property name="tokenAmount" type="java.lang.Double">
<column name="TOKEN_AMOUNT" precision="8" />
</property>
</class>
</hibernate-mapping>

I want to search by ppoCode and treasuryCode.
That is the where clause should look like: "where PPO_CODE = ? and TREASURY_CODE = ?".
But what actually comes is: "where (1=1)".

I used the following code:

PenDcrgAmountDtlDAO penDcrgAmountDtlDAO = new PenDcrgAmountDtlDAO();
PenDcrgAmountDtl penDcrgAmountDtl = new PenDcrgAmountDtl();
PenDcrgAmountDtlId penDcrgAmountDtlId = new PenDcrgAmountDtlId();
penDcrgAmountDtlId.setPpoCode(ppoCode);
penDcrgAmountDtlId.setTreasuryCode(treasuryCode);
penDcrgAmountDtl.setId(penDcrgAmountDtlId);

Collection col1 = penDcrgAmountDtlDAO.findByExample(penDcrgAmountDtl);


Here is findByExample code:

public List findByExample(PenDcrgAmountDtl instance) {
log.debug("finding PenDcrgAmountDtl instance by example");
try {

List results = getSession()
.createCriteria("com.ctmis.pension.hibernate.PenDcrgAmountDtl")
.add(Example.create(instance))
.list();
log.debug("find by example successful, result size: " + results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}

After debugging I found that "key-properties" are not checked for the where
clause append.
The problem can be solved by createQuery() call with model.id.ppoCode = ? etc.
But the thing is that we have to manually build the query.
Suppose next time we want to search by giving treasuryCode and slNo...

The dynamism of using Example.create() is needed.

Can anybody give a good solution?

I am using Hibernate 3.1.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 7:53 am 
Newbie

Joined: Thu Jan 25, 2007 3:24 am
Posts: 6
Anybody faced such a problem or have a solution?


Top
 Profile  
 
 Post subject: Pls give a solution
PostPosted: Mon Jan 29, 2007 2:08 am 
Newbie

Joined: Thu Jan 25, 2007 3:24 am
Posts: 6
Pls give a solution


Top
 Profile  
 
 Post subject: Pls reply
PostPosted: Tue Jan 30, 2007 2:04 am 
Newbie

Joined: Thu Jan 25, 2007 3:24 am
Posts: 6
Somebody pls reply, we can discuss.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 1:16 pm 
Newbie

Joined: Tue Aug 03, 2004 8:37 am
Posts: 3
Read the following topic. The solution is in the reply.
http://forum.hibernate.org/viewtopic.ph ... te+key+1+1

HTH.


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

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.