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