Hi There,
My env is
Hibernate 3.0.5
Postgres
I am not sure whether this is a defect with Hibernate or this had to be handled differently. I have three classes
MedicalHistory
Code:
<class name="com.peye.model.MedicalHistory" table="medical_history" schema="public">
<id name="id" type="long">
<column name="id" precision="12" scale="0" />
<generator class="native" />
</id>
:::::::::;;;
:::::::::::;;
<set name="contactLensHistory" cascade="all-delete-orphan">
<key>
<column name="medical_history_id" precision="12" scale="0" />
</key>
<one-to-many class="com.peye.model.ContactLensHistory" />
</set>
</class>
HistoryAttribute
Code:
<class name="com.peye.model.HistoryAttribute" table="history_attribute" schema="public">
<id name="id" type="long">
<column name="id" precision="12" scale="0" />
<generator class="native" />
</id>
<many-to-one name="medicalHistory" class="com.peye.model.MedicalHistory">
<column name="medical_history_id" precision="12" scale="0" />
</many-to-one>
::::::
:::::::
</class>
ContactLensHistory extends HistoryAttribute
Code:
<joined-subclass name="com.peye.model.ContactLensHistory" table="contact_lens_history" extends="com.peye.model.HistoryAttribute" schema="public" >
<key column="history_attribute_id"/>
<property name="answerType" type="short">
<column name="answer_type" precision="3" scale="0" />
</property>
</joined-subclass>
My code to save medicalhistory is
Code:
MedicalHistory medicalHistory = ((MedicalHistoryForm)form).getMedicalHistory();
//set the contactlens history in medical history
List<ContactLensHistory> clHistory = ((MedicalHistoryForm)form).getContactLensHistory();
//set the medicalhistory to contactlenshistory, the medicalhistory property is inherited from HistoryAttribute
for(ContactLensHistory cl : clHistory)
{
cl.setMedicalHistory(medicalHistory);
}
HashSet cls = new HashSet();
cls.addAll(clHistory);
medicalHistory.setContactLensHistory(cls);
MedicalHistoryDAO mdao = DAOFactory.DEFAULT.getMedicalHistoryDAO();
mdao.makePersistent(medicalHistory);
And the error I get is
19:41:11,757 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: null
19:41:11,757 ERROR JDBCExceptionReporter:72 - Batch entry 0
update public.contact_lens_history set medical_history_id=332 where history_attribute_id=333 was aborted. Call getNextException to see the cause.
19:41:11,757 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: 42703
19:41:11,757 ERROR JDBCExceptionReporter:72 - ERROR: column "medical_history_id" of relation "contact_lens_history" does not exist
19:41:11,777 ERROR AbstractFlushingEventListener:277 - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:74)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:69)
Hibernate is trying to set update the medical_history_id in the contact_lens_history, but it is available in history_Attribute table
which the contact_lens_history extends. Should I be mapping this differently if so how...
Thanks