2 Replies Latest reply: Oct 20, 2011 2:53 AM by Alexander Hartner RSS

ClassCastException with DB2 and JBoss 5.1.0 (Hibernate 3.4)

Alexander Hartner Expert

I 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

  • 1. Re: ClassCastException with DB2 and JBoss 5.1.0 (Hibernate 3.4)
    Wolf-Dieter Fink Master

    Looks like a mapping issue for DB2.

     

    Regarding the difference between community and enterprise version.

    The EAP version is a stable version of the community without the latest features and unstable/experimental components. Also the version is QA'ed and supported by the Red Hat subscriptions.

     

    So it might happen that the EAP version include bugfixes that will integrated in the community edition in a later release (maybe the next major release).

     

    If you have a subscription you should use the EAP version!

    (Remember that you will lost the support for EAP version if you replace components.)

  • 2. Re: ClassCastException with DB2 and JBoss 5.1.0 (Hibernate 3.4)
    Alexander Hartner Expert

    I tried using a later version of Hibernate from the Hibernate website. However so far I have not been able to patch it into JBoss. Hibernate Entity Manager 3.4 was the last independent release of the entity manager. From that version onwards Hibernate seems to have the entity manager and annotations included in a single package. I tried replacing Hibernate Annotations, EntityManager and Core JAR files with the latest 3.6 Hibernate JAR file, however this didn't work. If you have any suggestions on how I can get JBoss 5.1 to utilise a later version of Hibernate please let me know.

     

    Thanks inadvance.