ClassCastException with DB2 and JBoss 5.1.0 (Hibernate 3.4)
ejb3workshop Oct 19, 2011 7:20 AMI am getting a ClassCastException when pointing my application server (JBoss 5.1.0.GA) against DB2. When using it with other databases this problem does not occur. The problem is caused by me expecting a number object as response to a native query submitted via an entity manager as shown in the code snippet below. However rather then being a simple number object I am getting an object array containing a BigInteger with value 0 and an Integer with value 1 back.
Query query = m_entityManager.createNativeQuery("SELECT COUNT(ID) FROM JOBS WHERE TYPE=?");
query.setParameter(1, channelJobId);
Number number = (Number) query.getSingleResult();
The exception encountered is
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.lang.Number
at com.abc.Administrator.getJobs(Administrator.java:1106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73)
at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)....
This problem only occurs with JBoss 5.1.0 - Community Edition. Using JBoss Enterprise JBEAP 5.1.1 this issue does not occur. I have manage to trace this issue to a difference between these two different application server. JBoss 5.1.0 uses Hiberate EntityManager v3.4 while JBEAP 5.1.1 using Hibernate EnityManager [WORKING].
I wonder if anybody has got any idea if the fix from JBEAP made it's way into the community edition of Hibernate / JBoss and what version is recommended. I also tried upgrading the Hibernate packages included with JBoss using later versions of Hiberante but so far this hasn't worked at all. Any further insight into this matter would help me out a lot.
Thanks in advance
Alex