We have a problem with our HQL generator: by reflection (and some parameters) this component builds HQL sentences and generates needed joins, but it doesn't know if a relation is mapped with a component or many-to-one schema.
With Hibernate 2.1.x this HQL worked:
Code:
"FROM " + Pais.class.getName() + " AS pais JOIN pais.metaInfo AS minfo WHERE minfo.activo = true";
Now, with Hiberante 3.1.x the query fails. If explicit join is removed, query works fine (but our generator cannot remove it automatically):
Code:
"FROM " + Pais.class.getName() + " AS pais WHERE pais.metaInfo.activo = true";
Shouldn't HQL be totally transparent to mappings?
Stack trace is showed below.
Hibernate version: 3.1.3
Mapping documents:Code:
<hibernate-mapping>
<class name="Pais" table="Paises" lazy="true">
<id name="id" type="long" column="id">
<generator class="increment"/>
</id>
<component name="metaInfo" class="MetaInfo">
<property name="usuarioAlta" column="usuarioAltaMetaInfo" type="string" not-null="false"/>
<property name="fechaBaja" column="fechaBajaMetaInfo" type="timestamp" not-null="false"/>
<property name="fechaAlta" column="fechaAltaMetaInfo" type="timestamp" not-null="false"/>
<property name="activo" column="activoMetaInfo" type="boolean" not-null="false"/>
<property name="usuarioBaja" column="usuarioBajaMetaInfo" type="string" not-null="false"/>
</component>
<property name="nombre" column="nombre" type="string" not-null="true"/>
<property name="codigo" column="codigo" type="string" not-null="false"/>
<set name="localidades" access="field" inverse="true"
cascade="all-delete-orphan" lazy="true" batch-size="5">
<key column="pais" />
<one-to-many class="Localidad"/>
</set>
<set name="provincias" access="field" inverse="true"
cascade="all-delete-orphan" lazy="true" batch-size="5">
<key column="pais" />
<one-to-many class="Provincia"/>
</set>
<property name="codAS400" type="string" not-null="false"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():This is our test code:
Code:
String queryString = "FROM " + Pais.class.getName() + " AS pais JOIN pais.metaInfo AS minfo WHERE minfo.activo = true";
Query query = session.createQuery(queryString);
Full stack trace of any exception that occurs:Code:
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:317)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3268)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3060)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2938)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
Name and version of the database you are using:
We are using Oracle 9.
Thank you.