Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Ok, I am trying to map a simple inheritance java model into a hibernate application. I have a superclass of Person and two subclasses (ServiceMember and Dependent). I can insert a simple Person object with no problems but when I add on the inheritance it gives me errors noted below. I am using Apache Ant to build and insert the data. Also, I am letting Hibernate create and drop the tables initially to prevent any possible confilict in datatypes. I believe that my problem lies in the mapping file for the inheritance relationship. I am currently trying to use the table per subclass method discussed in the documentation. ( I appologize for lack of formatting on the code and xml here)
Hibernate version:
3.1.3
Mapping documents:
<?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>
<class name="person.Person" table="per">
<id name="id" column="per_id">
<generator class="native"/>
</id>
<property name="firstname"/>
<property name="lastname"/>
<property name="SSN"/>
<property name="gender"/>
<property name="bday"/>
<property name="address"/>
<property name="city"/>
<property name="zip"/>
<joined-subclass name="person.ServiceMember" table="sm">
<key column="sm_id"/>
<property name="rank"/>
<property name="branch"/>
<property name="nok"/>
<property name="deployed"/>
</joined-subclass>
<joined-subclass name="person.Dependent" table="dep">
<key column="dep_id"/>
<property name="relationship"/>
</joined-subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
package person;
import java.util.*;
import util.HiberateUtil;
public class DataManager {
public static void main(String[] args) {
DataManager mgr = new DataManager();
if (args[0].equals("list")) {
List serviceMembers = mgr.listServiceMembers();
for (int i = 0; i < serviceMembers.size(); i++) {
ServiceMember aServiceMember = (ServiceMember) serviceMembers.get(i);
System.out.println("Servicemember: " + aServiceMember.getLastname());
}
}else if(args[0].equals("store")){
mgr.storeServiceMember("LT", "NoName");
}
HibernateUtil.getSessionFactory().close();
}
private List listServiceMembers(){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List result = session.createQuery("from ServiceMember").list();
session.getTransaction().commit();
return result;
}
private void storeServiceMember(String rank, String lastname){
Session s = HibernateUtil.getSessionFactory().getCurrentSession();
ServiceMember sm = new ServiceMember();
sm.setRank(rank);
sm.setLastname(lastname);
s.save(sm);
s.getTransaction().commit();
}
}
Full stack trace of any exception that occurs:
I am getting the following error during the run phase:
Initial SessionFactory creation failed.org.hibernate.PropertyAccessException: IllegalArguementException occurred calling getter of person.Person.id
and further it states that it is caused by IllegalArgumentException calling the getter of person.Person.id.
I tested this without the inheritance and I can put Person objects into the DB without any issues it is only when I try to model the inheritance that it fails.
Name and version of the database you are using:
postgresql 1.2.0