-->
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.  [ 6 posts ] 
Author Message
 Post subject: Order of Persistent problem
PostPosted: Sun Oct 16, 2005 11:55 pm 
Newbie

Joined: Sun Oct 16, 2005 11:38 pm
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.18

Mapping documents:
<class name="com.hpt.apps.core.company.model.CompanyImpl" table="upc_company"
lazy="true">
<many-to-one name="Address"
class="com.hpt.apps.core.company.model.CompanyAddress" cascade="all"
column="ADDRESS_ID" />
</class>

<class name="com.hpt.apps.core.company.model.CompanyAddress"
table="UPC_COMPANY_ADDRESS">
<many-to-one name="Company" update="true"
class="com.hpt.apps.core.company.model.CompanyImpl"
column="COMPANY_ID" not-null="false"/>
</class>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Dear all!
I has an problem when mapping one-to-one relationship. I has two tables Company and CompanyAddress. When I create new Company, I assign CompanyAddress to Compnay. I mean that I want create new Company then, set CompanyId for CompanyAddress.CompanyId. But Hibernate persistent CompanyAddress first, after then is Company. So exception "SEVERE: ERROR: null value in column "company_id" violates not-null constraint" is raise.
I tried to set cascade="all" for many-to-one tag in CompanyAddress for hope that Hibernate will persistent Company first, but it fail.
To solve this problem I must set ComanyAddress is null, and after Company is persistented I re-set CompanyAddress. I wonder why hibernate don't do this automaticaly or my mapping document are wrong? Please help me! Thanks for all yours rely!!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 1:26 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
you must map the company_id column to the identifier property of the CompanyImpl class in the mapping document. read the documentation about the id element.


Top
 Profile  
 
 Post subject: Re
PostPosted: Mon Oct 17, 2005 5:26 am 
Newbie

Joined: Sun Oct 16, 2005 11:38 pm
Posts: 5
Thank dennisbyrne for rely! But above mapping is an excert from my mapping docment.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 12:35 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
you may want to post those portions of the mapping that are relevant to the error you are getting.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 2:32 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Did you try changing your many-to-one in CompanyAddress to be not-null="true"?

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 2:35 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
If only changing "not-null" from false to true, as nathanmoon said, doesn't work... check the code. If you have to set it to null and then to the value again, it may be that originally something is nulling the value of your property.


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