]
Vyacheslav Dimitrov commented on HHH-5817:
------------------------------------------
Don't mention it.
Passing char[] or byte[] to equal function of CriteriaBuilder throws
java.lang.ClassCastException (Vyacheslav Dimitrov)
-----------------------------------------------------------------------------------------------------------------------
Key: HHH-5817
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5817
Project: Hibernate Core
Issue Type: Bug
Components: entity-manager
Affects Versions: 3.6.0
Environment: Hibernate 3.6.0-Finale, derby db, mysql db, hsqldb
Reporter: Vyacheslav Dimitrov
Assignee: Gail Badner
Priority: Minor
Fix For: 3.6.1, 4.0.0.Alpha1
Attachments: hibernate_3_6_0.patch
We have byte[] field in one of our entity and we want to make query like this.
{code}
byte[] var = ...;
Predicate p = builder.equal(root.get("ourByteField"), var);
criteria.where(p);
{code}
But this code throws exception:
[java] Exception in thread "main" java.lang.ClassCastException: [B cannot
be cast to [Ljava.lang.Object;
[java] at
org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:349)
[java] at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:364)
[java] at
org.hibernate.ejb.criteria.CriteriaQueryCompiler$1$1.bind(CriteriaQueryCompiler.java:194)
[java] at
org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:247)
[java] at
org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:441)
[java] at ru.petrsu.nest.oqlite.test.TestParser.main(TestParser.java:92)
[java] Java Result: 1
because class AbstractQueryImpl has code:
{code}
...
else if ( value.getClass().isArray() ) {
final Object[] array = (Object[]) value;
...
{code}
We offer to change this "if" like this
{code}
...
else if ( value.getClass().isArray() && value.getClass().equals(Object[].class))
{
final Object[] array = (Object[]) value;
...
{code}
Due to this new condition we get what we want and our criteria works fine. (At least
ClassCastExceptio isn't occured).
Patch is attached (Also I can do pull request, if needed).
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: