-->
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: Query on superclass not working
PostPosted: Wed Dec 06, 2006 5:53 pm 
Newbie

Joined: Wed Dec 06, 2006 4:04 pm
Posts: 8
Location: New Hampshire
I am running Hibernate 3.2.1 against an Oracle 10G database using annotations in my java classes (no xml). Could you look at this and tell me if I have something set up wrong?

I have a superclass SUPER and three subclasses SUB1, SUB2, SUB3. My classes look like this:
Code:
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@DiscriminatorColumn(name = "DTYPE",
      discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue("S")
@Table(name="SUPER")
public class SUPER {
   protected String dtype;
   protected String name;

    public SUPER() {
    }

    @Column(name="DTYPE", insertable = false, updatable= false) //varchar2(31) in Oracle
    public String getDtype() {...
    public void setDtype(String dtype) {...

    @Column(name="NAME") //varchar2(200) in Oracle
    public String getName() {...
    public void setName(String name) {..

    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="SUPER_SEQ_GEN")
    @SequenceGenerator(name="SUPER_SEQ_GEN", sequenceName="SUPER_SEQ",initialValue=1,allocationSize=1)
    @Column(name = "ID", insertable = false, updatable = false)
    public int getId() {...
    public void setId(int id) {...
}

@Entity
@DiscriminatorValue("SUB1")
public class SUB1 extends SUPER{
   private SUPER supertype;
   
   public SUB1() {
   }

   @OneToOne
   @JoinColumn(name = "ID")
   public SUPER getSupertype() {
      return supertype;
   }

   public void setSupertype(SUPER supertype) {
      this.supertype = supertype;
   }

//INHERITED METHOD
   public String getName(){
      return name;
   }
   
   public void setName(String name){
      this.name = name;
   }
   String URI;
   
   @Column(name="URI")
   String getURI(){
      return URI;
   }
   
   void setURI(String uri){
      this.URI= uri;
   }

}

etc. on SUB2 and SUB3



I am running a JUnit test adding a record to SUPER. This works fine. I then try to do a select on the added record as follows:

Code:
SUPER i = new SUPER();
  Query t = getEm().createQuery("select i from SUPER i where ID=3");
  SUPER j = (SUPER)t.getSingleResult();


When this is run, I get the following generated SQL and the error:
    16:37:53,984 DEBUG AST:266 - --- HQL AST ---
    \-[QUERY] 'query'
    +-[SELECT_FROM] 'SELECT_FROM'
    | +-[FROM] 'from'
    | | \-[RANGE] 'RANGE'
    | | +-[DOT] '.'
    | | | +-[DOT] '.'
    | | | | +-[IDENT] 'domain'
    | | | | \-[IDENT] 'persistent'
    | | | \-[IDENT] 'SUPER'
    | | \-[ALIAS] 'i'
    | \-[SELECT] 'select'
    | \-[IDENT] 'i'
    \-[WHERE] 'where'
    \-[EQ] '='
    +-[IDENT] 'ID'
    \-[NUM_INT] '3'

    16:37:54,328 DEBUG AST:232 - --- SQL AST ---
    \-[SELECT] QueryNode: 'SELECT' querySpaces (SUB3,SUPER,SUB1,SUB2)
    +-[SELECT_CLAUSE] SelectClause: '{select clause}'
    | +-[ALIAS_REF] IdentNode: 'SUPER0_.ID as ID1_' {alias=i, className=domain.persistent.SUPER, tableAlias=SUPER0_}
    | \-[SQL_TOKEN] SqlFragment: 'SUPER0_.NAME as NAME1_, SUPER0_.DTYPE as DTYPE1_, SUPER0_.SUPER.SUPER_ID as SUPER4_1_, SUPER0_.name as name8_, SUPER0_.URI as URI8_, SUPER0_.name as name13_, SUPER0_.LANGUAGE_ID as LANGUAGE10_13_, SUPER0_.path as path13_, SUPER0_.LOCKED as LOCKED13_, SUPER0_.dtype as dtype13_, SUPER0_.SUB1IMAGE_ID as SUB1IMAGE12_13_, SUPER0_.AP_ID as AP8_13_, SUPER0_.CSET_ID as CSET9_13_, SUPER0_.CLASS_ID as CLASS13_13_, SUPER0_.SUB1WMIMAGE_ID as SUB1WM11_13_, SUPER0_.OWNER_ID as OWNER5_13_, SUPER0_.SUB1Level as SUB1Level13_, SUPER0_.SUB1Order as SUB1Order13_, SUPER0_.name as name14_, SUPER0_.clazz_ as clazz_'
    +-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[i], fromElementByTableAlias=[SUPER0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
    | \-[FROM_FRAGMENT] FromElement: '( select null as CSET_ID, null as CLASS_ID, null as SUB1IMAGE_ID, ID, null as AP_ID, null as SUB1Order, SUPER.SUPER_ID, null as LOCKED, null as SUB1Level, null as SUB1WMIMAGE_ID, null as URI, null as OWNER_ID, null as path, DTYPE, null as LANGUAGE_ID, NAME, 0 as clazz_ from SUPER union all select null as CSET_ID, null as CLASS_ID, null as SUB1IMAGE_ID, ID, null as AP_ID, null as SUB1Order, SUPER.SUPER_ID, null as LOCKED, null as SUB1Level, null as SUB1WMIMAGE_ID, URI, null as OWNER_ID, null as path, DTYPE, null as LANGUAGE_ID, NAME, 1 as clazz_ from SUB3 union all select CSET_ID, CLASS_ID, SUB1IMAGE_ID, ID, AP_ID, SUB1Order, SUPER.SUPER_ID, LOCKED, SUB1Level, SUB1WMIMAGE_ID, null as URI, OWNER_ID, path, DTYPE, LANGUAGE_ID, NAME, 2 as clazz_ from SUB1 union all select null as CSET_ID, null as CLASS_ID, null as SUB1IMAGE_ID, ID, null as AP_ID, null as SUB1Order, SUPER.SUPER_ID, null as LOCKED, null as SUB1Level, null as SUB1WMIMAGE_ID, null as URI, null as OWNER_ID, null as path, DTYPE, null as LANGUAGE_ID, NAME, 3 as clazz_ from SUB2 ) SUPER0_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=i,role=null,tableName=( select null as CSET_ID, null as CLASS_ID, null as SUB1IMAGE_ID, ID, null as AP_ID, null as SUB1Order, SUPER.SUPER_ID, null as LOCKED, null as SUB1Level, null as SUB1WMIMAGE_ID, null as URI, null as OWNER_ID, null as path, DTYPE, null as LANGUAGE_ID, NAME, 0 as clazz_ from SUPER union all select null as CSET_ID, null as CLASS_ID, null as SUB1IMAGE_ID, ID, null as AP_ID, null as SUB1Order, SUPER.SUPER_ID, null as LOCKED, null as SUB1Level, null as SUB1WMIMAGE_ID, URI, null as OWNER_ID, null as path, DTYPE, null as LANGUAGE_ID, NAME, 1 as clazz_ from SUB3 union all select CSET_ID, CLASS_ID, SUB1IMAGE_ID, ID, AP_ID, SUB1Order, SUPER.SUPER_ID, LOCKED, SUB1Level, SUB1WMIMAGE_ID, null as URI, OWNER_ID, path, DTYPE, LANGUAGE_ID, NAME, 2 as clazz_ from SUB1 union all select null as CSET_ID, null as CLASS_ID, null as SUB1IMAGE_ID, ID, null as AP_ID, null as SUB1Order, SUPER.SUPER_ID, null as LOCKED, null as SUB1Level, null as SUB1WMIMAGE_ID, null as URI, null as OWNER_ID, null as path, DTYPE, null as LANGUAGE_ID, NAME, 3 as clazz_ from SUB2 ),tableAlias=SUPER0_,origin=null,colums={,className=domain.persistent.SUPER}}
    \-[WHERE] SqlNode: 'where'
    \-[EQ] BinaryLogicOperatorNode: '='
    +-[IDENT] IdentNode: 'ID' {originalText=ID}
    \-[NUM_INT] LiteralNode: '3'

    16:37:55,359 DEBUG SQL:393 - select SUPER0_.ID as ID1_, SUPER0_.NAME as NAME1_, SUPER0_.DTYPE as DTYPE1_, SUPER0_.SUPER.SUPER_ID as SUPER4_1_, SUPER0_.name as name8_, SUPER0_.URI as URI8_, SUPER0_.name as name13_, SUPER0_.LANGUAGE_ID as LANGUAGE10_13_, SUPER0_.path as path13_, SUPER0_.LOCKED as LOCKED13_, SUPER0_.dtype as dtype13_, SUPER0_.SUB1IMAGE_ID as SUB1IMAGE12_13_, SUPER0_.AP_ID as AP8_13_, SUPER0_.CSET_ID as CSET9_13_, SUPER0_.CLASS_ID as CLASS13_13_, SUPER0_.SUB1WMIMAGE_ID as SUB1WM11_13_, SUPER0_.OWNER_ID as OWNER5_13_, SUPER0_.SUB1Level as SUB1Level13_, SUPER0_.SUB1Order as SUB1Order13_, SUPER0_.name as name14_, SUPER0_.clazz_ as clazz_ from ( select null as CSET_ID, null as CLASS_ID, null as SUB1IMAGE_ID, ID, null as AP_ID, null as SUB1Order, SUPER.SUPER_ID, null as LOCKED, null as SUB1Level, null as SUB1WMIMAGE_ID, null as URI, null as OWNER_ID, null as path, DTYPE, null as LANGUAGE_ID, NAME, 0 as clazz_ from SUPER union all select null as CSET_ID, null as CLASS_ID, null as SUB1IMAGE_ID, ID, null as AP_ID, null as SUB1Order, SUPER.SUPER_ID, null as LOCKED, null as SUB1Level, null as SUB1WMIMAGE_ID, URI, null as OWNER_ID, null as path, DTYPE, null as LANGUAGE_ID, NAME, 1 as clazz_ from SUB3 union all select CSET_ID, CLASS_ID, SUB1IMAGE_ID, ID, AP_ID, SUB1Order, SUPER.SUPER_ID, LOCKED, SUB1Level, SUB1WMIMAGE_ID, null as URI, OWNER_ID, path, DTYPE, LANGUAGE_ID, NAME, 2 as clazz_ from SUB1 union all select null as CSET_ID, null as CLASS_ID, null as SUB1IMAGE_ID, ID, null as AP_ID, null as SUB1Order, SUPER.SUPER_ID, null as LOCKED, null as SUB1Level, null as SUB1WMIMAGE_ID, null as URI, null as OWNER_ID, null as path, DTYPE, null as LANGUAGE_ID, NAME, 3 as clazz_ from SUB2 ) SUPER0_ where ID=3
    16:37:55,421 WARN JDBCExceptionReporter:77 - SQL Error: 904, SQLState: 42000
    16:37:55,421 ERROR JDBCExceptionReporter:78 - ORA-00904: "NAME": invalid identifier

    javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:647)
    at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:99)
    at domain.test.SUPERTest$2.test(SUPERTest.java:83)
    at domain.test.AbstractTest.test(AbstractTest.java:84)
    at domain.test.SUPERTest.testSUPERSelect(SUPERTest.java:71)
    at domain.test.TestRunner$1.runTest(TestRunner.java:47)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestCase.run(TestCase.java:111)
    at domain.test.TestRunner.main(TestRunner.java:50)
    Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.loader.Loader.doList(Loader.java:2214)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
    at org.hibernate.loader.Loader.list(Loader.java:2090)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:80)
    ... 11 more
    Caused by: java.sql.SQLException: ORA-00904: "NAME": invalid identifier

    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:213)
    at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:796)
    at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1031)
    at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:836)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1124)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1778)
    at org.hibernate.loader.Loader.doQuery(Loader.java:662)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
    at org.hibernate.loader.Loader.doList(Loader.java:2211)
    ... 19 more
Code:


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.