views:

279

answers:

1

did i encounter a hibernate bug or do i have an error i dont see:

select enty.number from EntityAliasName enty
  where enty.myId in
  (
    select cons.myId from Consens cons where cons.number in
    (
      select ord.number from Orders ord where ord.customer = :customer 
      and ord.creationDate <
      (
        select max(ord.creationDate) from Orders ord where ord.customer = :customer
      )
    )
  )

what i do get is the following:

org.hibernate.util.StringHelper.root(StringHelper.java:257)

Caused by: java.lang.NullPointerException
        at org.hibernate.util.StringHelper.root(StringHelper.java:257)
        at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1391)
        at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:54)
        at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1367)
        at org.hibernate.hql.ast.tree.FromElement.getIdentityColumn(FromElement.java:320)
        at org.hibernate.hql.ast.tree.IdentNode.resolveAsAlias(IdentNode.java:154)
        at org.hibernate.hql.ast.tree.IdentNode.resolve(IdentNode.java:100)
        at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:117)
        at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:113)
        at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:854)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1172)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRefLhs(HqlSqlBaseWalker.java:5167)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1133)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1993)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1932)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1476)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:580)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:288)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:231)
        at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
        at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
        at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
        at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
        at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:484)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:394)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)

using: Hibernate 3.3.2.GA / postgresql


Update:

i tryed to isloate the error by trying to execute each sub-clause for its own. i figured out that i get the same exception by just executing:

select enty.number from EntityAliasName enty

but if i execute the following it works:

select number from EntityAliasName enty

so now the question, Why?

maybe i should mention that EntityAliasName is an entity alias defined via:

<class name="package.EntityName"
         table="entities"
        entity-name="EntityAliasName"
        mutable="false"> ... </class>

Update 2:

I found a solution to the issue. My POJO was mapped this way:

<class name="package.EntityName"
             table="entities"
            entity-name="EntityAliasName"
            mutable="false">

  <composite-id>
    <key-property name="val1" column="val1" type="long"/>
    <key-property name="val2" column="val2" type="integer"/>
  </composite-id>

  <property name="id" column="entity_id" type="string" length="255" not-null="true"/>

  ...

</class>

there is an issue when having a composite id and using a property named id: HHH-1851 reported by Anthony Patricio. Changing the property name from id to entityId solved the issue:

Thanks to mdma for pointing me in the right direction.

A: 

I found a solution to the issue. My POJO was mapped this way:

<class name="package.EntityName"
             table="entities"
            entity-name="EntityAliasName"
            mutable="false">

  <composite-id>
    <key-property name="val1" column="val1" type="long"/>
    <key-property name="val2" column="val2" type="integer"/>
  </composite-id>

  <property name="id" column="entity_id" type="string" length="255" not-null="true"/>

  ...

</class>

there is an issue when having a composite id and using a property named id: HHH-1851 reported by Anthony Patricio. Changing the property name from id to entityId solved the issue:

<property name="entityId" column="entity_id" 
type="string" length="255" not-null="true"/>

Thanks to mdma for pointing me in the right direction.

just copied the answer from my update above, to close it as answered and keep accept ratio up

ManBugra