-->
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: One To Many with shared composite key
PostPosted: Sat Nov 17, 2007 10:42 am 
Newbie

Joined: Sat Nov 17, 2007 9:24 am
Posts: 5
Hi All,
I have One to Many Association betweeb UserPreferences and UserColumns Tables.
PerefrenceId is the primary key of the UserPreferences. And i am using sequence for it.

PrefrenceId is the foriegn key used for assocoation. But this PerefrenceId is also shared by the composite key in the UserColumns.

When i have to save the UserPrefrerence like below:


UserPreferences userPrefrences=new UserPreferences();

UserColumns userColumns=new UserColumns();


UserColumnsId userColumnId=new UserColumnId();
userColumnId.setColumnId(new Long(11));

userColumns.setUserColumnsId(userColumnsId);
userColumns.setPosition(new Long(10));

userPreferences.addUserColumns(userColumns);
userPrefrences.setReportType(new Long(0));
userPrefrences.setUserId(new Long(0));

getHibernateTemplate().saveOrUpdate(userPrefrences);

it gives key voilation exception can not insert null into the PrefrerenceId column of the userColumns table. i am not setting it for UserColumns. Beacuse PreferenceId in the parent table UserPreference is being inserted by a sequence. so while inserting the UserPreference i don't know what is the PreferenceId.

But if i set the preferenceId in UserCoulmns it works fine.

How should i save the association.

Thanks in advance \
Pushpendra


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.