Servlet异常+类抛出异常+ Glassfish + Netbeans + JPA实体+ Vaadin [英] Servlet Exception + Class Cast Exception + Glassfish + Netbeans + JPA Entities + Vaadin

查看:130
本文介绍了Servlet异常+类抛出异常+ Glassfish + Netbeans + JPA实体+ 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传递到另一个。有几种解决方案可以解决这个问题:


  • 将所有代码放入一个WAR中。

  • 在WAR之间使用某种形式的远程处理。序列化处理类加载器问题。

  • 尝试将所有WAR加入到单个EAR中。如果这不起作用,请将所有代码放入MANIFEST.MF中EAR类路径中的JAR。


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆