-->
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: Unable to save - Self reference
PostPosted: Thu May 11, 2006 5:15 pm 
Newbie

Joined: Thu May 11, 2006 5:00 pm
Posts: 5
I have a table Telephone Address that has a foreign key to itself (Telephone Address Parent). The foreign key is nullable.

I am not able to save a simple Telephone Address entity because of the many to one relationship with the Foreign key. When I comment the same, it works (which is not ideal). Can someone help?

Below is the hibernate xml

<hibernate-mapping>
<class name="com.albertsons.components.centraltelecom.hibernate.vo.TelephoneAddressHibernate" table="TELEPHONE_ADDRESS">

<many-to-one name="telephoneAddress" class="com.albertsons.components.centraltelecom.hibernate.vo.TelephoneAddressHibernate" fetch="select">
<column name="TELEPHONE_ADDRESS_PRNT_ID" precision="22" scale="0" />
</many-to-one>

<set name="telephoneAddresses" inverse="true">
<key>
<column name="TELEPHONE_ADDRESS_PRNT_ID" precision="22" scale="0" />
</key>
<one-to-many class="com.albertsons.components.centraltelecom.hibernate.vo.TelephoneAddressHibernate" />
</set>
</hibernate-mapping>

I am using Hibernate 3.1 beta4 and Oracle 9i

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 2:23 pm 
Newbie

Joined: Thu May 11, 2006 5:00 pm
Posts: 5
I did not receive any reply from anyone in this regard. But what I did notice was that the key of my table was based on a sequence. And this is somehow interfereing with the self reference when the self refernced value is null. Somehow null is not accepted as a valid key value in self refernce.

I tried various unsaved value options for the primary key in my hbm file, but in vain.

Ultimately I changed the many-to-one relationship with self to a property. I manually changed the self reference in the VO to a long value

Something like

public class TelephoneAddress
{
private Long parentTelephoneAddressKey;
}

instead of

public class TelephoneAddress
{
private TelephoneAddress parentTelephoneAddress;
}

The above was good for me from business perspective. So it was fine. I am not sure what could be the actual solution for my problem statement.


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.