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
|
|