Hibernate version: Hibernate 3.1CR2, Hibernate Annotations 3.1 beta 9, Hibernate EntityManager 3.1 beta 9
Name and version of the database you are using: HSQLDB 1.8.0
Hello,
I am currently testing the different inheritance strategies supported by Hibernate. In one of my tests, I have three classes, Pet, Cat and Dog. Cat and Dog inherit from Pet, and inheritance type is set to "TABLE_PER_CLASS".
Here is my code :
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Pet implements java.io.Serializable {
protected int id;
protected String name;
protected double weight;
...
}
@Entity
@Table(name = "TABLEPERCLASS_CAT")
public class Cat extends Pet {
private int lives;
...
}
@Entity
@Table(name = "TABLEPERCLASS_DOG")
public class Dog extends Pet {
private int numBones;
...
}
Then, here is the script which create needed tables :
create table TABLEPERCLASS_CAT (
ID bigint,
LIVES bigint,
NAME varchar,
WEIGHT double,
primary key (ID)
);
create table TABLEPERCLASS_DOG (
ID bigint,
NUMBONES bigint,
NAME varchar,
WEIGHT double,
primary key (ID)
);
Then, I try to list all pets, here is the corresponding method :
public Collection<Pet> findAllPets() {
...
try {
Query q = entityManager.createQuery("from Pet");
Collection resultList = q.getResultList();
return resultList;
} catch (RuntimeException e) {
throw e;
}
finally {
entityManager.close();
}
}
}
The only result I have is a Hibernate error :
2006-04-19 15:39:58,460 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: -22, SQLState: S0002
2006-04-19 15:39:58,476 ERROR [org.hibernate.util.JDBCExceptionReporter] - Table not found in statement [select petx0_.id as id7_, petx0_.weight as weight7_, petx0_.name as name7_, petx0_.lives as lives8_, petx0_.numBones as numBones9_, petx0_.clazz_ as clazz_ from ( select null as numBones, null as lives, name, weight, id, 0 as clazz_ from Pet union select null as numBones, lives, name, weight, id, 1 as clazz_ from TABLEPERCLASS_CAT union select numBones, null as lives, name, weight, id, 2 as clazz_ from TABLEPERCLASS_DOG ) petx0_]
When analysing the request above, i remark that it doesn't seem to correspond to the table-per-class strategy as the request try to access a "Pet" table...
So I was wondering if table-per-request was well supported in the current Hibernate release. Or am i doing something wrong ?
|