Java:转换为自身时的异常(?) [英] Java: exception when casting to itself(?)
问题描述
我正在使用Oracle WebLogic,Netbeans 6.9.1。
我有以下几行代码:
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();
他们抛出异常:
java.lang.ClassCastException: entity.Items cannot be cast to entity.Items
即使看起来不可能,我在SO上也看到了类似的问题:在这里
作者没有发布解决方案,但其中一位参与者对不同的类加载器做了很好的假设。
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.
同时如果我使用getResultList然后在JSP中使用它,它工作正常。但我不能在servlet代码中进行转换。
Meanwhile if i use getResultList and then work with it in JSP, it works fine. But i cant make casting work in servlet code.
我如何在weblogic中解决这个问题?
How can i fix this in weblogic?
推荐答案
它没有具体解决您的问题,但如果您使用的是WebLogic Server 10.3.x或其附近,则可以使用Web应用程序作为该发行版的一部分来解决类加载问题。
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.
您可以在此处阅读更多相关信息: http://download.oracle.com/docs/cd/E17904_01/web.1111/e13706/classloading.htm#WLPRG495
You can read more about it here: http://download.oracle.com/docs/cd/E17904_01/web.1111/e13706/classloading.htm#WLPRG495
它应与早期版本的WebLogic Server兼容,因此您可以将其与建议的解决方法结合使用以获得解决方案。
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.
这篇关于Java:转换为自身时的异常(?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!