This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate not picking values from PK Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate not picking values from PK" Watch "Hibernate not picking values from PK" New topic
Author

Hibernate not picking values from PK

Sachin Dare
Greenhorn

Joined: May 04, 2004
Posts: 12
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate not picking values from PK
 
Similar Threads
Taken From the Java EE 5 Tutorial
Help Needed....
[ hibernate ]composite
Many-to-many composite ID
adding to a table with no primary keys