This appears to be a common problem, and I understand it is usually with the mapping, but I cannot figure it out in my case. I have googled both this forum and the internet at large, plus read through "Java persistence with Hibernate" by Bauer and King, but I am still stumped.
I have a "typed" one-to-one association as described
here. I have the key values set to not-null, but when I go to save to the database I get the following error where you can clearly see that hibernate is trying to enter null values:
Quote:
10:42:59,120 ERROR [JDBCExceptionReporter] Batch entry 0 insert into public.exam_diagnosis_and_management_options (diagnostic_code_id, index, exam_medical_decision_id) values (6, NULL, NULL) was aborted. Call getNextException to see the cause.
10:42:59,120 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 23502
10:42:59,120 ERROR [JDBCExceptionReporter] ERROR: null value in column "exam_medical_decision_id" violates not-null constraint
From what I have read, I am guessing that Hibernate is trying to do an insert, and then plans on doing an update to set those, though I cannot figure out a way to make it do it all in one insert. I cannot use inverse=true since it is a one-to-one relationship. I am using session.merge() to save the code. Any help would be greatly appreciated.
My mapping files are:
Code:
<hibernate-mapping>
<class name="com.wg.common.bean.ExamMedicalDecision" table="exam_medical_decision">
<id name="id" type="integer">
<column name="id" />
<generator class="sequence">
<param name="sequence">exam_medical_decision_id_seq</param>
</generator>
</id>
...
<one-to-one name="diagnosisAndOptions1" cascade="all" lazy="false">
<formula>1</formula>
<formula>id</formula>
</one-to-one>
<one-to-one name="diagnosisAndOptions2" cascade="all" lazy="false">
<formula>2</formula>
<formula>id</formula>
</one-to-one>
<one-to-one name="diagnosisAndOptions3" cascade="all" lazy="false">
<formula>3</formula>
<formula>id</formula>
</one-to-one>
<one-to-one name="diagnosisAndOptions4" cascade="all" lazy="false">
<formula>4</formula>
<formula>id</formula>
</one-to-one>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.wg.common.bean.ExamDiagnosisAndManagementOptions" table="exam_diagnosis_and_management_options" >
<composite-id >
<key-property name="index" type="integer">
<column name="index" not-null="true"></column>
</key-property>
<key-many-to-one name="examMedicalDecision" class="com.wg.common.bean.ExamMedicalDecision">
<column name="exam_medical_decision_id" not-null="true"></column>
</key-many-to-one>
</composite-id>
<many-to-one name="diagnosticCode" class="com.wg.common.bean.DiagnosticCode" lazy="false">
<column name="diagnostic_code_id"/>
</many-to-one>
<set name="options" table="exam_diagnosis_and_management_options_xref" lazy="false">
<key>
<column name="exam_diagnosis_and_management_options_index" not-null="true"></column>
<column name="exam_diagnosis_and_management_options_emd_id" not-null="true"></column>
</key>
<element column="exam_management_option" type="text" not-null="true"/>
</set>
</class>
</hibernate-mapping>