wood burning stoves 2.0*
The moose likes JBoss/WildFly and the fly likes java.lang.ClassCastException: java.lang.Integer cannot be cast to com.user Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "java.lang.ClassCastException: java.lang.Integer cannot be cast to com.user" Watch "java.lang.ClassCastException: java.lang.Integer cannot be cast to com.user" New topic

java.lang.ClassCastException: java.lang.Integer cannot be cast to com.user

Sunny Diaz

Joined: Mar 07, 2011
Posts: 16

Hi, I have a strange problem coming for some strange reason i don't know.
I am in a process of migrating from jboss4 to jboss5 and everything was workign perfectly fine in jboss4 and since i start to start my application in jboss5 i get this exception.

What i have been doing in the query was getting the results from two tables to show statistics and these results i get in the object array.
on index 0 always was coming user records and on index 1 it always came the integer value.
but in jboss5 now i get the results opposite and i get this castexception... for some reason at index 0 it is coming integer value and at index 1 it is coming user records.

I have checked the mysql query which is perfectly fine and working fine in jboss4 and in mysql editor also.

any idea what could be reason? hibernate?
l am using hibernate3 with jboss4 and with jboss5 also the same.

using ehcache as well for mapping classes which was working also fine in jboss4 but now in jboss5 i get the warning that can not find specific configuration... could it be the reason of the exception???

Please help!

Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10068

You'll have to show us some code (including the part where you create and run the JPQL/HQL), the entire exception stacktrace and maybe even the generated SQL.

[My Blog] [JavaRanch Journal]
Sunny Diaz

Joined: Mar 07, 2011
Posts: 16

java.lang.ClassCastException: java.lang.Integer cannot be cast to com.user
at com.data.StatisticsManager.executeTopRatingQuery(StatisticsManager.java:507)
at com.data.StatisticsManager.getStatWeekly(StatisticsManager.java:364)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at flex.messaging.services.remoting.adapters.JavaAdapter.invoke(JavaAdapter.java:421)
at flex.messaging.services.RemotingService.serviceMessage(RemotingService.java:183)
at flex.messaging.MessageBroker.routeMessageToService(MessageBroker.java:1495)
at flex.messaging.endpoints.AbstractEndpoint.serviceMessage(AbstractEndpoint.java:882)
at flex.messaging.endpoints.amf.MessageBrokerFilter.invoke(MessageBrokerFilter.java:121)
at flex.messaging.endpoints.amf.LegacyFilter.invoke(LegacyFilter.java:158)
at flex.messaging.endpoints.amf.SessionFilter.invoke(SessionFilter.java:44)
at flex.messaging.endpoints.amf.BatchProcessFilter.invoke(BatchProcessFilter.java:67)
at flex.messaging.endpoints.amf.SerializationFilter.invoke(SerializationFilter.java:146)
at flex.messaging.endpoints.BaseHTTPEndpoint.service(BaseHTTPEndpoint.java:278)
at flex.messaging.MessageBrokerServlet.service(MessageBrokerServlet.java:315)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardC

this is the part of the stack trace...

the function where i execute this query is

private List<TopEntry> executeTopRatingQuery(User user, Query query, int start, int max) {

List<TopEntry> result = new ArrayList<TopEntry>();

if (user == null) {

for (Object[] row : (List<Object[]>)query.getResultList()) {

TopEntry entry = new ToplistEntry(((User)row[0]).toPlayer(), getIntValue(row[1]), -1);


and the other function is

public List<TopEntry> getStatWeekly(int start, int max, User user) {
String TABLE = "weekly";
EntityTransaction tx = em.getTransaction();
try {
Query query = em.createNativeQuery(NATIVE_QUERY_WEEKLY.replaceFirst("\\?1", TABLE), "UserMapOne");
return executeTopRatingQuery(user, query, start, max);
finally {
if (tx.isActive())

finally the query is

public static final String NATIVE_QUERY_WEEKLY =
"select us.*, in_week as val from ?1 v, user us " +
"where v.user_id = us.id and us.disabled = 0 " +
"order by in_week desc, us.username";
Sunny Diaz

Joined: Mar 07, 2011
Posts: 16

But still i feel there is not issue in the code.. as it is all working perfectly fine in the jboss4. i guess there could be problem with hibernate or cache? what do you think?
subject: java.lang.ClassCastException: java.lang.Integer cannot be cast to com.user