[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5817?page=c...
]
Steve Ebersole commented on HHH-5817:
-------------------------------------
Yep, equals( Object[].class ) was a really bad choice here.
That is only ever going to be true if the array is literally an Object array and not any
other type of class.
This really ought to operate on the "array component type". Open a new issue if
you could please.
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.
For more information on JIRA, see:
http://www.atlassian.com/software/jira