-->
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.  [ 9 posts ] 
Author Message
 Post subject: Problem inserting Children using composite IDs
PostPosted: Fri May 28, 2004 11:29 am 
Newbie

Joined: Thu May 27, 2004 9:14 am
Posts: 11
I have poured over the docs and have been using Hibernate for several years so.... Anyway I have a parent child bi-directional relationship and am inserting the parent with the collection of children set.

Both the Parent and Children use composite IDs (I know they suck and are a pain in the ass but I have no choice).

I'm basically creating the collection of children the calling the setter on the parent and then persisting the parent.

Parent: Calldetl
Child: Calldetl_Tax

The error I receive (from the child record - the parent inserts fine) is: cannot insert NULL into ("SMARTPAY"."CALLDETL_TAX"."CARRIERCODE")

This field is actually part of the PK for the parent and part of the FK for the child and the error is basicallysaying that I'm not setting the field in the child. Anyway this is never explicitly set as it comes from the composite key in the parent and I'm sure it's populated there because I traced it.

BTW it's not the insert/update problem as I am seeing the SQL and it all looks good....

Thanks,

Cory

Pertinent parts of the Parent and Child follow:
THE PARENT
<class
name="com.verisign.smartpay.dto.Calldetl"
table="CALLDETL"
>

<composite-id name="comp_id" class="com.verisign.smartpay.dto.CalldetlPK" unsaved-value="none" >
<key-property
name="ddate"
column="DDATE"
type="java.sql.Timestamp"
length="7"
/>
<key-property
name="carriername"
column="CARRIERNAME"
type="java.math.BigDecimal"
length="22"
/>
<key-property
name="marketname"
column="MARKETNAME"
type="java.math.BigDecimal"
length="22"
/>
<key-property
name="tablekey"
column="TABLEKEY"
type="java.math.BigDecimal"
length="22"
/>
</composite-id>
snip
<!-- associations -->
<!-- bi-directional one-to-many association to CalldetlTax -->
<set
name="calldetlTaxs"
lazy="false"
inverse="true"
cascade="all"
>
<key>
<column name="CALLDETL_DDATE" />
<column name="CARRIERCODE" />
<column name="REGIONCODE" />
<column name="TABLEKEY" />
</key>
<one-to-many
class="com.verisign.smartpay.dto.CalldetlTax"
/>
</set>

THE CHILD

<class
name="com.verisign.smartpay.dto.CalldetlTax"
table="CALLDETL_TAX"
>

<composite-id name="comp_id" class="com.verisign.smartpay.dto.CalldetlTaxPK" unsaved-value="any" >
<key-property
name="id"
column="ID"
type="java.math.BigDecimal"
length="22"
/>
<key-property
name="createdDate"
column="CREATED_DATE"
type="java.sql.Timestamp"
length="22"
/>
</composite-id>

<property
name="chargeTotal"
type="java.math.BigDecimal"
column="CHARGE_TOTAL"
not-null="true"
length="6"
/>
<property
name="taxTotal"
type="java.math.BigDecimal"
column="TAX_TOTAL"
not-null="true"
length="6"
/>
snip
<!-- bi-directional many-to-one association to Calldetl -->
<many-to-one
name="calldetl"
class="com.verisign.smartpay.dto.Calldetl"
not-null="true"
>
<column name="CALLDETL_DDATE" />
<column name="CARRIERCODE" />
<column name="REGIONCODE" />
<column name="TABLEKEY" />
</many-to-one>


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 5:08 pm 
Newbie

Joined: Thu May 27, 2004 9:14 am
Posts: 11
Did I not provide e[/b]nough relevant information for someone to post a reply? Did I run over your dog on the way to work? Did I piss in your Cherios?

Give a little love!!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 5:11 pm 
Newbie

Joined: Thu May 27, 2004 9:14 am
Posts: 11
This project is for real time call rating. If I can't pull this off I won't be working in IT ever again.

Gavin - I've been meaning to see Australia so if they can my ass from this job could I crash on your couch for awhile?

Or somebody could help me!!! Please.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 5:13 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Stop whining and explain your problem in a way that everyone can understand it. If the SQL insert is "not a problem", why do you say that "insert null" is a problem?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 5:15 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Oh and the key columns you use in the parent are not the foreign key columns you are using. They have to be the same, of course.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 5:29 pm 
Newbie

Joined: Thu May 27, 2004 9:14 am
Posts: 11
LOL.

christian wrote:
Oh and the key columns you use in the parent are not the foreign key columns you are using. They have to be the same, of course.


The fields I believe are OK in the mapping. It was XDoclet generated and I checked it against the example from the documentation for consistencies sake: The field names are going to be different between the parent PK and child FK in some cases.

<class name="eg.Parent">
<id name="id" column="id"/>
....
<set name="children" inverse="true" lazy="true">
<key column="parent_id"/>
<one-to-many class="eg.Child"/>
</set>
</class>

<class name="eg.Child">
<id name="id" column="id"/>
....
<many-to-one name="parent" class="eg.Parent" column="parent_id"/>
</class>

They are even the same order.

What I'm basically saying is that Hibernate should be populating the children's FK fields from the parent's composite ID. The error message indicates that this is not happening is Hibernate is in fact trying to insert a null value for CarrierCode which is definitely being set in the parent's composite id CARRIERNAME field.

Thanks,

Cory


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 6:12 pm 
Newbie

Joined: Thu May 27, 2004 9:14 am
Posts: 11
Just to clarify the fields are the same but named inconsistently (confusing I know but our dba's attempt at using certain naming conventions for new tables)

Parent Child Table FK back to Parent
DDATE == CALLDETL_DDATE
CARRIERNAME == CARRIERCODE
MARKETNAME == REGIONCODE
TABLEKEY == TABLEKEY


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 29, 2004 1:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ugh. Please lets just ignore my drunk 2AM posts, and pretend they never happened....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 01, 2004 9:04 am 
Newbie

Joined: Thu May 27, 2004 9:14 am
Posts: 11
Hey gang I'm still at a loss to solve this one.

If I didn't explain clearly enough before I have 2 classes. Both use composite IDs. The primary key of the parent class is set and persists fine. When I then assign a collection of children to the parent and persist the parent and children together Hibernate seems to not be able to populate the foriegn key fields of the children (which are the primary key of the parents.

Are there any known issues regarding the usage of one to many persistence (or bi-directional) persistence using Hibernate 2.1.2 and composite IDs?.

BTW the PKs for the children have been created properly as well.

Thanks,

Cory


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