InheritanceType.TABLE_PER_CLASS question
pimpf Mar 7, 2006 10:40 AMBecause the EJB3.0 FD spec doesn't say to much about that kind of inheritance strategy, I looked up at the following examples:
[url]http://docs.jboss.org/ejb3/app-server/tutorial/tableperinheritance/table.html[/url]
I played with them but an exception occured:
javax.ejb.EJBException: org.hibernate.exception.SQLGrammarException: could not execute query
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
*****
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2148)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1129)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:39)
****
Caused by: java.sql.SQLException: ORA-00942: table or view does not exist
I have the following class definition:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Pet implements java.io.Serializable {
private int id;
private String name;
private int weight;
*****
-----------------------------------------
@Entity
@Table(name="CAT")
public class Cat extends Pet
{
int lives;
public int getLives()
{
return lives;
}
public void setLives(int lives)
{
this.lives = lives;
}
}
---------------------------------------------
@Entity
@Table(name="DOG")
public class Dog extends Pet
{
private int numBones;
public int getNumBones()
{
return numBones;
}
public void setNumBones(int numBones)
{
this.numBones = numBones;
}
}
and a stateless session bean:
public List getAllPets( ){
return em.createQuery("from Pet p").getResultList();
}
************************
I have only two table - CAT and DOG exactly as provided in the example above.
Can anyone see where is the problem - should I have table PET?!?