-->
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.  [ 1 post ] 
Author Message
 Post subject: VERY simple inheritance scenario is broken now
PostPosted: Tue May 24, 2005 7:07 pm 
Beginner
Beginner

Joined: Fri Oct 15, 2004 2:54 pm
Posts: 33
Location: Austin, TX
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.2
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.txdx.pojo">
<class name="PatientPOJO" table="patients">
    <id name="id" column="patient_id" type="long" unsaved-value="null">
      <generator class="hilo"/>
    </id>
    <property name="salutation"  type="string" length="4"  not-null="true" />
    <property name="firstName"   type="string" length="25" not-null="true" />
    <property name="initial"     type="string" length="1"  not-null="false"/>
    <property name="lastName"    type="string" length="25" not-null="true" />
  ... buncha others deleted ...
    <property name="wwebsite"    type="string" length="50" not-null="false"/>
    <!-- TODO: link to authorized contact here, 1-to-1 contact null OK -->
    <property name="serialVersionUID" type="long"/>
    <bag name="Rxs" cascade="all" inverse="true" lazy="false" order-by="rxDate">
      <key column="patient_id"/>
      <one-to-many class="com.txdx.pojo.RxPOJO"/>
    </bag>
    <!--
    <set name="Rxs" cascade="all" inverse="true" lazy="false">
      <key column="patient_id"/>
      <one-to-many class="com.txdx.pojo.Rx"/>
    </set>
    -->
  </class>
</hibernate-mapping>

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

Full stack trace of any exception that occurs:

org.hibernate.MappingException: Unknown entity: com.txdx.database.Patient
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:553)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1022)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:408)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:82)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:432)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:427)
at com.txdx.database.Retriever.savePatient(Retriever.java:85)
... my stuff from there on out
Name and version of the database you are using:
MySQL, latest
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:



OK, this has GOT to be the simplest inheritence scenario ever. The mapping file above produces PatientPOJO, and I extend that class as follows:

Code:
package com.txdx.database;
public class Patient extends com.txdx.pojo.PatientPOJO {
   static final long serialVersionUID = 1L;

   public Patient() {
      super();
   }

   public void setDOB(String dateString) {
...
         }
}


I was doing this originally in hibernate 2.x, dropped the project, and have since restarted work on it, using hibernate 3. Anyuway, the only reason I extended the class is to put in some business functions so that I could rebuild the POJOs with hibernate. Like I said, THE simplest inheritance scheme ever. As you can see, I followed the inheritance rules as laid out in section 4.2 of the manual. The thing just won't save (saveorupdate). I did a sanity check by testing the instance with instanceof, and it is both a Patient and a PatientPOJO. When I cast it to PatientPOJO, I get the same error. When I assign a Patient to a PAtientPOJO, I get the same error. The only way to make this data persist is to instantiate a PatientPOJO and set its values with setters pulling from Patient getters. Ugh. I should be able to just persist Patient because it is also PatientPOJO, right?


I looked in the migration guide, and searched the forum, but if it's been answered before I didn't come up with the right keywords to get me to the thread.

--PK

_________________
--Pierce Krouse


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.