-->
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: Circular dependency for many-to-one.. what to do?
PostPosted: Wed Mar 15, 2006 7:04 pm 
Newbie

Joined: Thu Sep 23, 2004 2:35 pm
Posts: 5
Hello,

Here is my problem.. I have HbmPerson class mapped as Many-to-one mapped in HbmCustomerAccount and

many-to-one HbmCustomerAccount mapped in HbmCustomer object..

So, when I want to insert into a DB, I get an an expeption:

JDBCExceptionReporter - SQL Error: 0, SQLState: 23502
JDBCExceptionReporter - ERROR: null value in column "acct_id" violates not-null constraint

The problem I think is that when Hibernate wants to insert HbmPerson object, it needs an acct_id from HbmCustomerAccount, but that can't be inserted till HbmPerson is.. so both classes depend on each other for insert..

How do I go about solving this? Mapping things as Set works.. I can set inverse-true attribute and Hibernate delayes the insert of the set objects till it obtains the id from the main one.. But in this case, I need and person_id of the Person in Account Table and I want to be able to figure out which account a person belongs to from the ca_person table itself..

I'm sure it is a common question.. but I could not find an answer... Should I be mapping it differently?

Thanks in advance...

Dmitry.


Hibernate version: 3.1

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.ca.db.persistent" >
<class name="HbmCustomerAccount" table="ca_account">
<id name="id" column="acct_id" type="long">
<generator class="assigned" />
</id>


<many-to-one name="primaryContact" cascade="all" unique="true" column="primary_contact_id" class="HbmPerson"/>

</class>
</hibernate-mapping>



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.ca.db.persistent" >
<class name="HbmPerson" table="ca_person">
<id name="id" column="person_id" type="long">
<generator class="sequence" >
<param name="sequence">ca_person_person_id_seq</param>
</generator>
</id>

..... other properties go here ......

<many-to-one class="HbmCustomerAccount" name="account" unique="true" column="acct_id"/>

</hibernate-mapping>




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.