GWT对持久实体的反序列化(JPA) [英] GWT Deserialisation of Persistent Entities (JPA)

查看:162
本文介绍了GWT对持久实体的反序列化(JPA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发托管在weblogic应用程序服务器上的Java / GWT应用程序。我将EJB3.0与EclipseLink一起用作持久层。可惜的是,我的GWT在反序列化持久化实体方面存在问题。

这可能会对您有所帮助,以便知道,我


  • 在我的类路径中包含EclipseLink-Library(包括 javax.persistence.Entity

  • 从数据库或persistence-manager接收持久化对象 - 我使用标准Java代码创建对象
  • 使用Eclipse IDE for Java EE开发人员开发和部署我正在用GWT-Plugin(GWT 2.1.0)编译我的GWT代码 - 我的源代码被拆分成几个项目

  • 非常确定,客户端发生的问题,因为我的服务器的HTTP响应在我的工作和我的不工作的例子中是相同的

  • 尝试修补 javax.persistence.Entity 并尝试使用包含 javax.persistence.Entity 的几个库,但没有任何内容帮助仅使用此代码的最小项目

  • WO rks很好,但是这个集成在我们项目环境中的代码不起作用



更新:看起来像这样整个主题是 rpc.enhancedClasses 的一些问题。我添加了我生成的 .gwt.rpc - 文件的有趣内容。这似乎是不正常的,通过HTTP传输的数据是相同的,虽然这些.rpc文件不同。
这些链接可能很有趣: RemoteService.gwt.xml 增强类文档



在我的服务器中提供了类 SerialClass ;接口如下所示:

  public interface GreetingService扩展RemoteService {
List< SerialClass> greetServer();
}

我的onModuleLoad() - 方法获取这些实例并创建一个浏览器信息:

  public void onModuleLoad(){
GreetingServiceAsync server =(GreetingServiceAsync)GWT.create(GreetingService.class );
server.greetServer(new AsyncCallback< List< SerialClass>>(){
public void onFailure(Throwable caught){
}

public void onSuccess ; SerialClass> result){

String resultString =;
try {
for(SerialClass serial:result){
if(serial == null){
resultString + =null;
} else {
resultString + =>+ serial.id +<;
}
}
} catch(Throwable t){
Window.alert(failed to process);
}

Window.alert(success:+ resultString);
}
});


我的服务器看起来像这样:

  public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService {
public List< SerialClass> greetServer()抛出IllegalArgumentException {
List< SerialClass> list = new ArrayList< SerialClass>();
for(int i = 0; i <100; i ++){
list.add(new SerialClass());
}
返回列表;
}
}

案例1 =>一切正常



我使用 SerialClass (无需任何注释,或者使用除Entity之外的任何注释 - 例如 javax.persistence.PersistenceContext 可以正常工作):

  // @Entity 
public class SerialClass实现Serializable,IsSerializable {
public int id = 4711;
}

弹出窗口包含(如预期的):

 成功:> 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< > 4711< 

通过HTTP发送的数据如下所示:

  // OK [4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711, 2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2, 4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711, 2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2, 4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711, 2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2, 4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711, 2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2, 4711,2,4711,2,4711,2,4711,2,100,1,[java.util.ArrayList / 3821976829,serial.shared.SerialClass / 10650133],0,6] 

生成的 .xml.rpc - 文件(4F138A4EA095EA4C468507AF3CA19D8F.g wt.rpc)包含:

  my.package.SerialClass,true,true,false,false,my.package.SerialClass / 2805025871,2805025871 
[Lmy.package.SerialClass ;, true,true,false,false,[Lmy.package.SerialClass; / 600614154,600614154

案例2 =>它根本不工作

我正在使用 SerialClass

  @Entity 
public class SerialClass implements Serializable,IsSerializable {
public int id = 4711;
}

我的弹出窗口包含(这是我的问题) :

 成功:> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null> 2< null 

通过HTTP发送的数据看起来像这样(完全一样!):

  //确定[4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2 ,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711 ,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2 ,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711 ,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2 ,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711 ,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2 ,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711 ,2,4711,2,4711,2,4711,2,4711,2,4711,2,100,1,[ 的java.util.ArrayList / 3821976829, serial.shared.SerialClass / 10650133],0,6 ] 

生成的 .xml.rpc - 文件(E81A9E44 448F41D2EC63CD508632C10B.gwt.rpc)包含:

  my.package.SerialClass,true,true,false,false,my.package。 SerialClass / 2805025871,2805025871 
@ ClientFields,my.package.SerialClass,id
[Lmy.package.SerialClass; true,true,false,false,[Lmy.package.SerialClass; / 600614154,600614154

没有可疑的日志记录输出 - 既不在服务器上,也不在客户端上。所有HTTP响应都有返回码200.



我当前的解决方法

我我将尝试创建传输对象作为我的SerialClass的副本 - 这些传输对象看起来完全一样,但不会有@Entity注释。

或者我可以尝试使用 RequestFactory (感谢@Hilbrand提示)。



我真的不知道如何解决这个问题,我真的很感谢任何建议,提示,技巧,链接等。

解决方案

我们找到了解决方案!感谢帮助我的每个人!



GWT无法序列化我注释类的对象,因为 .gwt.rpc

解决方案是创建仅包含所有javascript,html和rpc的一个war文件资源。这个war文件现在还包含servlet定义(在 web.xml 中)。我们的java代码被部署在单独的模块(jar文件)中,这些文件被war文件引用。


I am currently developing Java/GWT-application which is hosted on a weblogic application server. I am using EJB3.0 with EclipseLink as persistence layer. Sadly my GWT has problems to deserialize persistent entities.

It might be helpful for you to know, that I

  • have the EclipseLink-Library in my classpath (including javax.persistence.Entity)
  • am not recieving the persistence objects from a database or persistence-manager - I am creating the objects with standard java code
  • use Eclipse IDE for Java EE Developers for development and deploying and I am compiling my GWT code with the GWT-Plugin (GWT 2.1.0) - my source code is split up in several projects
  • am pretty sure, that the problems occures on client side, since the HTTP response of my server is the same in my working and in my not working example
  • tried to patch javax.persistence.Entity and tried to include several libraries which included javax.persistence.Entity but nothing was helping
  • a minimal project with just this code works fine, but this code integrated in our project environment does not work

UPDATE: it looks like this whole topic is some problem with rpc.enhancedClasses. I added the interesting contents of my generated .gwt.rpc-files. It seems to be unnormal, that the data transfered over HTTP is the same, although these .rpc files differ. These links might be interesting: RemoteService.gwt.xml and the documentation for enhances classes

In my server provides a list of instances of class SerialClass; the interface looks like this:

public interface GreetingService extends RemoteService {
    List<SerialClass> greetServer();
}

My onModuleLoad()-Method gets those instances and creates a browser-popup with the information:

public void onModuleLoad() {
    GreetingServiceAsync server = (GreetingServiceAsync) GWT.create(GreetingService.class);
    server.greetServer(new AsyncCallback<List<SerialClass>>() {
        public void onFailure(Throwable caught) {
        }

        public void onSuccess(List<SerialClass> result) {

            String resultString = "";
            try {
                for (SerialClass serial : result) {
                    if (serial == null) {
                        resultString += "null ";
                    } else {
                        resultString += ">" + serial.id + "< ";
                    }
                }
            } catch (Throwable t) {
                Window.alert("failed to process");
            }

            Window.alert("success:" + resultString);
        }
    });

}

My server is looking like this:

public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService {
    public List<SerialClass> greetServer() throws IllegalArgumentException {
        List<SerialClass> list = new ArrayList<SerialClass>();
        for (int i = 0; i < 100; i++) {
            list.add(new SerialClass());
        }
        return list;
    }
}

Case 1 => everything works fine

I am using this SerialClass (either without any annotation, or with any annotation other than Entity - for example javax.persistence.PersistenceContext works fine):

//@Entity
public class SerialClass implements Serializable, IsSerializable {
    public int id = 4711;
}

The popup contains (as expected):

success:>4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711< >4711<

The data sent over HTTP looks like this:

//OK[4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,100,1,["java.util.ArrayList/3821976829","serial.shared.SerialClass/10650133"],0,6]

The generated .xml.rpc-file (4F138A4EA095EA4C468507AF3CA19D8F.gwt.rpc) contains:

my.package.SerialClass, true, true, false, false, my.package.SerialClass/2805025871, 2805025871
[Lmy.package.SerialClass;, true, true, false, false, [Lmy.package.SerialClass;/600614154, 600614154

Case 2 => its not working at all

I am using this SerialClass:

@Entity
public class SerialClass implements Serializable, IsSerializable {
    public int id = 4711;
}

My popup contains (THIS IS MY PROBLEM):

success:>2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null >2< null 

The data sent over HTTP looks like this (exactly the same!):

//OK[4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,4711,2,100,1,["java.util.ArrayList/3821976829","serial.shared.SerialClass/10650133"],0,6]

The generated .xml.rpc-file (E81A9E44448F41D2EC63CD508632C10B.gwt.rpc) contains:

my.package.SerialClass, true, true, false, false, my.package.SerialClass/2805025871, 2805025871
@ClientFields,my.package.SerialClass,id
[Lmy.package.SerialClass;, true, true, false, false, [Lmy.package.SerialClass;/600614154, 600614154

There is no suspicious logging output - neither on server, nor on client. All HTTP-responses have return code 200.

My current workaround

I am going to try to create transfer objects as a copy of my SerialClass - those transfer objects will look exactly the same, but will not have the @Entity annotation.

Alternatively I could try to use the RequestFactory (thanks to @Hilbrand for the hint).

I really don't know how to solve that problem and I'm really thankful about any suggestions, hints, tips, links, etc.

解决方案

Ok, we found a solution! Thanks for everyone that helped me!

GWT was unable to serialize the objects of my annotated class, because the .gwt.rpc-files were not accessible via servlet context.

The solution was to create just one war file containing all javascript, html and rpc resources. This war file now also contains the servlet definitions (in the web.xml). Our java code is deployed in seperate modules (jar files), which are referenced by that war file.

这篇关于GWT对持久实体的反序列化(JPA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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