[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2494?page=c...
]
Juergen Englisch commented on HHH-2494:
---------------------------------------
This patch works:
Replace following beautiful line of code (line:48) in the SubqueryExpression-Class:
final SessionImplementor session = ( (CriteriaImpl) criteria ).getSession(); //ugly!
with
final SessionImplementor session = getSession(criteria);
and introduce a getSession-Method:
private SessionImplementor getSession(Criteria criteria) {
if (criteria instanceof CriteriaImpl) {
return ( (CriteriaImpl) criteria ).getSession(); //ugly!
} else if (criteria instanceof CriteriaImpl.Subcriteria) {
return getSession( ((CriteriaImpl.Subcriteria) criteria).getParent());
} else {
throw new IllegalStateException("Unknown session implementation.");
}
}
ClassCastException from Subquery with Criteria created via
DetachedCriteria
---------------------------------------------------------------------------
Key: HHH-2494
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2494
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.2
Environment: Hibernate 3.2.2, Informix 10
Reporter: Christopher Pierce
If I create a DetachedCriteria object, then call "createCriteria" to on it,
then pass a Subquery to the new Criteria, I get this exception:
java.lang.ClassCastException: org.hibernate.impl.CriteriaImpl$Subcriteria cannot be cast
to org.hibernate.impl.CriteriaImpl
at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:43)
at
org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:334)
at
org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:82)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
example:
public class EntityOne {
private long entityOneID
private EntityTwo entityTwo
...
}
public class EntityTwo {
private long entityTwoID
private EntityThree entityThree
...
}
public class EntityThree {
private long entityThreeID;
private String name;
...
}
DetachedCriteria subselect = DetachedCriteria.forClass(EntityThree.class);
subselect.add(Restrictions.like("name","test",MatchMode.START)).setProjection(Projections.id());
DetachedCriteria mainselect = DetachedCriteria.forClass(EntityOne.class);
mainselect.createCriteria("entityTwo").add(Subquery.in("entityThree",subselect));
mainselect.getExecutableCriteria(session).list();
This results in the ClasCastException error.
--
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