-->
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.  [ 2 posts ] 
Author Message
 Post subject: Not able to save a subclass
PostPosted: Wed Feb 22, 2006 9:11 pm 
Newbie

Joined: Tue Jan 31, 2006 11:04 pm
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 23, 2006 12:47 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You have to use HistoryAttribute as the class that the one-to-many maps to, because ContactLensHistory isn't a complete mapping. You'll have to rely on business logic to ensure that only ContactLensHistory objects are put into the set.

You can use the where="sql condition" to optimize selects, but you still have to ensure that no non-ContactLensHistory objects go into the set.


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