[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3828?page=c...
]
Agustino Alim commented on HHH-3828:
------------------------------------
I also face the same issue
Class[] clazz = {SubCompany.class, SubDirector.class};
Session session = HibernateUtil.getSession();
Criteria c = session.createCriteria(Company.class);
c.add(Restrictions.in("class", clazz));
I get this error
Exception in thread "main" java.lang.ClassCastException: java.lang.Class cannot
be cast to java.lang.String
at org.hibernate.type.StringType.toString(StringType.java:67)
at org.hibernate.type.NullableType.nullSafeToString(NullableType.java:117)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:158)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1728)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1699)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1589)
at org.hibernate.loader.Loader.doQuery(Loader.java:696)
Criteria: Restriction whith class does not work
-----------------------------------------------
Key: HHH-3828
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3828
Project: Hibernate Core
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.3.1
Environment: Oracle, HSQLDB
Reporter: Kai Prünte
The following line does not work:
Restrictions.eq("class", Bike.class)
because
SingleTableEntityPersister.getDiscriminatorSQLValue()
returns the discriminator value quoted with single quotes. However JDBC needs the string
without quotes.
Workaround:
Restrictions.eq("class", Bike.class.getName())
This works fine for the default discriminator values
Patch in CriteriaQueryTranslator.getTypedValue(Criteria subcriteria, String propertyName,
Object value):
if(stringValue != null && stringValue.length() > 2 &&
stringValue.startsWith("'") &&
stringValue.endsWith("'") ) {
// remove the single quotes
stringValue = stringValue.substring(1, stringValue.length() - 1);
}
--
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