-->
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.  [ 3 posts ] 
Author Message
 Post subject: Composite key is not returning values
PostPosted: Tue Feb 10, 2009 12:49 am 
Newbie

Joined: Thu Oct 30, 2008 3:26 am
Posts: 10
I have a table with composite primary key. In this key, one column is auto increment column.
When i saved the object, the auto generated key of the composite primary key is not being updated in the saved object. I mean the auto generated value is not being populated in the saving object.

It perfectly populated when there is single column primary key with auto increment.

Please help me in resolving this.

Hibernate version: 3.2
Mapping documents:
<hibernate-mapping>
<class name="com.cmcltd.afpis.dbsystem.dbobjects.Printfeature"
table="PRINTFEATURE" schema="F7TMS">
<composite-id>
<key-property name="pfid" type="java.lang.Long">
<column name="PFID" precision="22" scale="0" />
</key-property>
<key-property name="digitNmbr"
type="com.cmcltd.afpis.enums.HibDigitCodes">
<column name="DIGIT_NMBR" />
</key-property>
</composite-id>

<property name="sid" type="java.lang.Long">
<column name="SID" precision="22" scale="0" />
</property>
<property name="impressionType"
type="com.cmcltd.afpis.enums.HibImpressionType" not-null="true">
<column name="IMPRESSION_TYPE"></column>
</property>

<property name="mnt">
<column name="MNT" not-null="true" />
</property>
<property name="status" type="java.lang.String">
<column name="STATUS" length="10" not-null="true" />
</property>
</class>
Code between sessionFactory.openSession() and session.close():

SlipImage si = new SlipImage();
si.setSid(12);
si.set..()
...
getHibernateTemplate().save(si);

Name and version of the database you are using: MySQL 5.1

Please help me in resolving this problem.

Thanks in advance,
Sridhar Reddy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2009 1:39 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Hi Sridhar ,

As per my understanding, if you are using composite key in any entity, you have to assign values to all the properties of composite id.

Hibernate doesn't help here.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2009 2:18 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Hi Sridhar,

If you have a column as auto generated column then why cant you just keep that column as the primary key. Why do you want to have a composite primary key at all? Coz anyways the auto generated column is going to be unique.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.