-->
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.  [ 2 posts ] 
Author Message
 Post subject: one-to-many relationship between parent and child , child
PostPosted: Tue Dec 02, 2008 1:40 am 
Newbie

Joined: Tue Dec 02, 2008 1:27 am
Posts: 1
i am getting a problem while establishing "0ne-to-many" relation between tables Accessor and ACCSR_RI_SEC_AUTH

because "ACCSR_RI_SEC_AUTH" has a composite key and when i write set as

in accessor,it has only on column as a key. while mapping it searches column="ACCSR_KEY" as FK in ACCSR_RI_SEC_AUTH
but here "ACCSR_KEY" is one of the columns in composite key.

so it throws me an error while saving something like "can not insert Null for ACCSR_KEY"
so can u suggest me some solution
here are my mappings files

for accessor----------
<hibernate-mapping>
<class name="com.singulartruth.service.security.app.entity.Accessor" table="ACCSR" dynamic-update="true"
optimistic-lock="version" mutable="true" polymorphism="implicit">

<id name="key" column ="ACCSR_KEY">
<generator class="sequence">
<param name="sequence">SEQ_ACCSR_KEY</param>
</generator>
</id>

<set name="securityAuthCodeSet" table="ACCSR_RI_SEC_AUTH">
<key column="ACCSR_KEY"/>
<one-to-many class="com.singulartruth.service.security.app.entity.AccessAuthorization"/>
</set>
and for ACCSR_RI_SEC_AUTH---------

<hibernate-mapping>
<class name="com.singulartruth.service.security.app.entity.AccessAuthorization" table="ACCSR_RI_SEC_AUTH">

<composite-id>
<key-property column="ACCSR_KEY" name="key"/>
<key-property column="RSRC_ITEM_KEY" name="resourceItemKey"/>
<key-property column="SEC_ACCES_CODE" name="securityAccessCode"/>
<key-property column="START_DATE" name="startDate"/>
</composite-id>
</hibernate-mapping>

Key in the set is one of columns of composite key so accessor is not getting exact FK to set key value automatically by set


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2008 4:19 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 8:25 am
Posts: 46
Location: Saint Petersburg, Russian Federation
That's correct behavior. <composite-id> element defines a natural key, i.e. it's user responsibility to fill in the necessary properties before storing the object. I.e. if you have a not-null constraint on ACCSR_KEY column and don't fill that property at the java level you get an integrity violation exception and that's correct.

Solution is to fill all necessary values at the java code if you're using natural keys or switch to surrogate keys and generate them automatically.


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