-->
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: Composite Key problem
PostPosted: Sat Aug 13, 2011 10:13 am 
Newbie

Joined: Sat Aug 13, 2011 10:08 am
Posts: 1
Hello World,
I am new to Hibernate. I have created composite primary key like
<composite-id name="applicationPK" class="com.test.alert.ApplicationPK" >
<key-property name="alert_id" column="ALERT_ID" type="int" />
<key-property name="cn" column="CN" type="int" />
</composite-id >

And my Primary Key class like

public class ApplicationPK implements Serializable {
private int alertId;
private int cn;
//getter setter for above fields.
}

And POJO class looks like this –

public class AlertUserVO {
private int alertId;
private int cn;
private String status;
private ApplicationPK compositePK;

// getter setter of above fields.
}

And in my test class I have following code for inserting record –

//Hibernate code for getting session, transaction etc.
AlertUserVO obj = new AlertUserVO();
ApplicationPK compositePK = new ApplicationPK();
compositePK.setAlertId(11);
compositePK.setCn(19);

obj.setStatus(“Test”);
obj.setCompositePK(compositePK);

The problem here is it’s always setting values for alert_id and cn as zero.
But if instead I use following code it sets values properly –

alertUserVO.setAlertId(12);
alertUserVO.setCn(9);

Why it is picking up the values from POJO class instead of PK class.
Is there any way to take the values from PK class?

Please help me.


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.