[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1895?page=c...
]
Victor Sergienko commented on HHH-1895:
---------------------------------------
I found that it's extremely easy to work around it: use "from table, table ...
where" join instead of "join".
http://victorsergienko.com/hibernate-join-bug-createfromjoinelement/
HqlSqlWalker throws NullPointerException with explicit joins and
component mapping
----------------------------------------------------------------------------------
Key: HHH-1895
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1895
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.1.3
Environment: Oracle 9i, Hibernate 3.1.3
Reporter: Victor Suarez
Priority: Minor
HqlSqlWalker throws a NPE if a explicit join is used with fields that are mapped with
component mapping. If explicit join is removed and implicit join is used, the HQL works
fine. This kind of problem didn't occur with Hibernate2.
Examples (hbm below):
The query:
String query = "FROM " + Pais.class.getName() + " AS pais JOIN
pais.metaInfo AS minfo WHERE minfo.activo = true";
fails with this stacktrace:
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)
This one works fine:
String query = "FROM " + Pais.class.getName() + " AS pais WHERE
pais.metaInfo.activo = true";
With this behaviour, HQL seems not to be totally transparent to mappings.
Mapping file:
<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>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira