[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2667?page=c...
]
Nick Folder commented on HHH-2667:
----------------------------------
"But how do I need to change my code which is using the Criteria API (see my first
comment on this ) ?"
From the Reference Guide (anyway it sucks ;-) ...
15.4. Associations
You may easily specify constraints upon related entities by navigating associations using
createCriteria().
List cats = sess.createCriteria(Cat.class)
.add( Restrictions.like("name", "F%") )
.createCriteria("kittens")
.add( Restrictions.like("name", "F%") )
.list();
note that the second createCriteria() returns a new instance of Criteria, which refers to
the elements of the kittens collection.
The following, alternate form is useful in certain circumstances.
List cats = sess.createCriteria(Cat.class)
.createAlias("kittens", "kt")
.createAlias("mate", "mt")
.add( Restrictions.eqProperty("kt.name", "mt.name") )
.list();
(createAlias() does not create a new instance of Criteria.)
Note that the kittens collections held by the Cat instances returned by the previous two
queries are not pre-filtered by the criteria! If you wish to retrieve just the kittens
that match the criteria, you must use a ResultTransformer.
List cats = sess.createCriteria(Cat.class)
.createCriteria("kittens", "kt")
.add( Restrictions.eq("name", "F%") )
.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
.list();
Iterator iter = cats.iterator();
while ( iter.hasNext() ) {
Map map = (Map) iter.next();
Cat cat = (Cat) map.get(Criteria.ROOT_ALIAS);
Cat kitten = (Cat) map.get("kt");
}
'illegal attempt to dereference collection' when using
auto-join
----------------------------------------------------------------
Key: HHH-2667
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2667
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.
--
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