3

Im working with Oracle WebLogic, Netbeans 6.9.1. I have the following lines of code:

Query query=entityManager.createNamedQuery("Items.findById").setParameter("id", Integer.parseInt((String) request.getParameter("id")));
Items it=(Items) query.getSingleResult();

and they throw an exception:

java.lang.ClassCastException: entity.Items cannot be cast to entity.Items

Even if that seem impossible, i saw similar question on SO: here Author havent published the solution but one of participants made a good asumption about different class loaders.

Meanwhile if i use getResultList and then work with it in JSP, it works fine. But i cant make casting work in servlet code.

How can i fix this in weblogic?

Community
  • 1
  • 1
Anton
  • 3,006
  • 3
  • 26
  • 37

3 Answers3

1

It doesn't solve your problem specifically, but if you're using WebLogic Server 10.3.x or thereabouts, there is a web application provided as part of that distribution that you can use to troubleshooting classloading issues.

You can read more about it here: http://download.oracle.com/docs/cd/E17904_01/web.1111/e13706/classloading.htm#WLPRG495

It should be compatible with earlier versions of WebLogic Server, so you could use that in conjunction with the proposed workarounds to get to a solution.

kevinpowe
  • 496
  • 3
  • 5
0

See this similiar question with a proposed workaround.

Community
  • 1
  • 1
Matt Handy
  • 29,855
  • 2
  • 89
  • 112
0

This indeed looks like a classloading problem.

This earlier answer of mine explains how to verify this assumption.

Unfortunately, classloading problems are difficult and painful. There is no easy fix, only to try to understand what classloaders are loading what classes in which order, and trying to play around with your classloaders, classes and jars to eliminate the problem. Also, analyse the most recent changes in your app before this error appeared - these can provide the key to understanding the root cause.

I am not familiar with the classloading scheme in WebLogic, so unfortunately I can't give you any more specific advice.

Community
  • 1
  • 1
Péter Török
  • 114,404
  • 31
  • 268
  • 329