Servlet异常+类抛出异常+ Glassfish + Netbeans + JPA实体+ Vaadin [英] Servlet Exception + Class Cast Exception + Glassfish + Netbeans + JPA Entities + Vaadin
问题描述
$ b
StandardWrapperValve [Vaadin Servlet]:PWC1406:Servlet.service()用于servlet Vaadin Servlet抛出异常
java.lang.ClassCastException:com.delhi.entities.Category不能转换为com.delhi.entities.Category
when我尝试在glassfish v2上运行我的webapps。
Category是一个JPA实体对象
到服务器日志是:
for(Category c:categories){
mymethod();
}
类别来源于:
列表<类别> categories = q.getResultList();
有什么想法会出错?
这是一个类加载器问题。如果一个类由不同的类加载器加载,则不能将对象分配给对方。您可能已经将一个对象从一个WAR传递到另一个。有几种解决方案可以解决这个问题:
I get this error:
StandardWrapperValve[Vaadin Servlet]: PWC1406: Servlet.service() for servlet Vaadin Servlet threw exception java.lang.ClassCastException: com.delhi.entities.Category cannot be cast to com.delhi.entities.Category
when I try to run my webapps on glassfish v2.
Category is a JPA entity object
the offending code according to the server log is:
for (Category c : categories) {
mymethod();
}
categories is derived from:
List<Category> categories = q.getResultList();
Any idea what went wrong?
This is a class loader issue. If a class is loaded by different class loaders, it's objects cannot be assigned to each other. You have probably passed an object from one WAR into another one. There are several options to resolve this:
- Put all your code into a single WAR.
- Use some form of remoting between your WARs. Serialization takes care of the class loader problem.
- Try putting all you WARs into a single EAR. If that doesn't work, put all code into JARs that are on the EAR's Classpath in the MANIFEST.MF.
这篇关于Servlet异常+类抛出异常+ Glassfish + Netbeans + JPA实体+ Vaadin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!