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