[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2739?page=c...
]
Steve Ebersole closed HHH-2739.
-------------------------------
Resolution: Fixed
You mean something along the lines of:
public void testIt() {
Session s = sf.openSession();
System.out.println( "to-one dereference
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
s.createQuery( "from Cat c where c.mate.color = 'black'" );
System.out.println(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
System.out.println( "to-many dereference
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
s.createQuery( "from Cat where c.kittens.color = 'black'" );
System.out.println(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
s.close();
}
With output like:
to-one dereference ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
to-many dereference ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
org.hibernate.QueryException: illegal attempt to dereference collection
[cat0_.uid.kittens] with element property reference [color] [from Cat c where
c.kittens.color = 'black']
at
org.hibernate.hql.ast.tree.DotNode$1.buildIllegalCollectionDereferenceException(DotNode.java:46)
at org.hibernate.hql.ast.tree.DotNode.checkLhsIsNotCollection(DotNode.java:512)
at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:221)
at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:94)
at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:90)
at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:728)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1216)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4041)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3525)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
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:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
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:1623)
at Test.testIt(Test.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
???
'illegal attempt to dereference collection' when referencing
a single-valued association in an implicit join
------------------------------------------------------------------------------------------------------------
Key: HHH-2739
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2739
Project: Hibernate3
Issue Type: Bug
Affects Versions: 3.2.3, 3.2.4, 3.2.4.sp1
Environment: I have found that behaviour in version 3.2.4.sp1 and 3.2.3 (I
didn't test 3.2.4 pre sp1)
Database: ORACLE 10g
Reporter: Martin Kouba
After upgrading to the latest Hibernate version I got this error.
I try to use a statement like this
from cat c where c.mate.id = 13
the expected resulting SQL should be something like
SELECT * FROM CAT C WHERE C.MATE_ID = 13
which is much more performant than making a join
from cat c join c.mate m where m.id = 13
which would result in something like that
SELECT * FROM CAT C INNER JOIN MATE M ON C.MATE_ID = M.ID WHERE M.ID = 13
This works as expected in 3.1.3, 3.2.0 and 3.2.2
It doesn't work with version 3.2.3 and with 3.2.4.sp1.
As test case you can take the example from the documentation chapter 5.1.16
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="eg">
<class name="Cat" table="CATS">
<id name="id" column="uid"
type="long">
<generator class="hilo"/>
</id>
<property name="birthdate" type="date"/>
<property name="color" not-null="true"/>
<property name="sex" not-null="true"/>
<property name="weight"/>
<many-to-one name="mate"/>
<set name="kittens">
<key column="MOTHER"/>
<one-to-many class="Cat"/>
</set>
<joined-subclass name="DomesticCat"
table="DOMESTIC_CATS">
<key column="CAT"/>
<property name="name" type="string"/>
</joined-subclass>
</class>
<class name="eg.Dog">
<!-- mapping for Dog could go here -->
</class>
</hibernate-mapping>
c = new Cat();
c.setMate(new Cat());
c.persist();
int id = c.getId();
List results = session.createQuery("from Cat as c where c.mate.id = 16).list();
according to manual section 14.5 this should work
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#queryhql-i...
Ok, I hope this is clear enough and the test case is clear enough as well.
This is a major stopper for an upgrade. I have reported that on June 11th
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2667
But it seems that others used the same case to report a similar issue regarding automatic
joins.
According to Christian Bauer automatic joins are no longer supported, closed the case and
told me to reopen it again.
So to all others please do not add comments to this case if it is not about it. And to
the Hibernate developers: Greate work you are doing but please I think the issue was clear
when I reported it the first time. It is quite easy to reproduce and occurs quite often in
a medium size project.
Gratitude
Martin
--
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