Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GWT&x2B;JPA持久性。未找到异常源代码_Gwt_Jpa_Persistence_Requestfactory - Fatal编程技术网

GWT&x2B;JPA持久性。未找到异常源代码

GWT&x2B;JPA持久性。未找到异常源代码,gwt,jpa,persistence,requestfactory,Gwt,Jpa,Persistence,Requestfactory,我正在尝试使用JPA创建一个简单的DB连接。 它可以正常工作,但当我尝试向客户端抛出异常时,会出现以下错误: [ERROR] [browsereditor] - Line 210: No source code is available for type javax.persistence.EntityExistsException; did you forget to inherit a required module? [ERROR] [browsereditor] - Line 212:

我正在尝试使用JPA创建一个简单的DB连接。 它可以正常工作,但当我尝试向客户端抛出异常时,会出现以下错误:

[ERROR] [browsereditor] - Line 210: No source code is available for type javax.persistence.EntityExistsException; did you forget to inherit a required module?

[ERROR] [browsereditor] - Line 212: No source code is available for type javax.persistence.EntityNotFoundException; did you forget to inherit a required module?
我在开发模式中没有错误,它编译得很好,但是当加载应用程序模块时,我就在那里得到了错误

我在server/Composer和client/Presenter类中具有所需的导入

import javax.persistence.EntityExistsException;
import javax.persistence.EntityNotFoundException;
我还向类路径和构建路径添加了以下JAR:

javax.persistence.jar

jpa-annotations-source.jar(http://code.google.com/p/google-web-toolkit/issues/detail?id=1830#c14)

我还尝试添加到gwt.xml

<source path='client'/>
<source path='shared'/>
<source path='server'/>
///Presenter.class中createComposer(以上)的激发请求

req.fire(new Receiver<ComposerProxy>() {

                        public void onSuccess(ComposerProxy arg0) {

                            ComposerProxy comp;
                            comp = arg0;
                        }

                        public void onFailure(Throwable caught)
                                throws Throwable {
                            // Convenient way to find out which exception
                            // was thrown.
                            try {
                                throw caught;
                            } catch (EntityExistsException e) {

                            } catch (EntityNotFoundException e) {

                            }
                        }});
                }});


[ERROR] [browsereditor] - Line 210: No source code is available for type javax.persistence.EntityExistsException; did you forget to inherit a required module?
[ERROR] [browsereditor] - Line 212: No source code is available for type javax.persistence.EntityNotFoundException; did you forget to inherit a required module?
requ.fire(新接收器(){
成功时公共无效(Composer代理arg0){
作曲家代理公司;
comp=arg0;
}
失败时的公共无效(可丢弃)
扔掉的{
//查找哪种异常的便捷方法
//被扔了。
试一试{
扔抓;
}捕获(EntityExistsException e){
}捕获(EntityNotFounde异常){
}
}});
}});
[错误][browsereditor]-第210行:没有可用于javax.persistence.EntityExistsException类型的源代码;您是否忘记继承所需的模块?
[错误][browsereditor]-第212行:没有可用于javax.persistence.EntityNotFoundException类型的源代码;您是否忘记继承所需的模块?

您根本不能在客户端GWT代码中使用诸如
EntityExistsException
EntityNotFoundException
之类的类型

这些是普通的Java类,GWT不知道如何将它们转换为JavaScript

在客户端代码中只能使用非常有限的部分外部库。这些库(例如)是专门为客户端设计和准备的,需要在应用程序的模块中继承它们的GWT模块

我认为你真正想做的是:

public void onFailure(ServerFailure failure) throws Throwable {
    if(failure.getExceptionType().equals("javax.persistence.EntityExistsException")){
          ...
    }else if(failure.getExceptionType().equals("javax.persistence.EntityNotFoundException")){
       ...
    }
}

因为您可以将服务器端异常的类型读取为字符串,请参阅和。

您根本不能在客户端GWT代码中使用诸如
EntityExistsException
EntityNotFoundException
之类的类型

这些是普通的Java类,GWT不知道如何将它们转换为JavaScript

在客户端代码中只能使用非常有限的部分外部库。这些库(例如)是专门为客户端设计和准备的,需要在应用程序的模块中继承它们的GWT模块

我认为你真正想做的是:

public void onFailure(ServerFailure failure) throws Throwable {
    if(failure.getExceptionType().equals("javax.persistence.EntityExistsException")){
          ...
    }else if(failure.getExceptionType().equals("javax.persistence.EntityNotFoundException")){
       ...
    }
}

因为您可以将服务器端异常的类型读取为字符串,请参阅和。

感谢Piotr的帮助

以下是我最终所做工作的代码:

客户端中的代码

req.fire(new Receiver<ComposerProxy>() {

                        public void onSuccess(ComposerProxy arg0) {

                            ComposerProxy comp;
                            comp = arg0;
                        }

                        public void onFailure(ServerFailure failure) {

                            serverError.getServerError(failure,
                                    "onAddButtonClicked");

                        }

                    });
服务器中的服务

public static Composer createComposer(String name) throws Throwable {
    EntityManager entityManager = entityManager();
    Composer comp = new Composer();

    try {
        comp.setName(name);
        comp.setId(1);

        entityManager.getTransaction().begin();
        entityManager.persist(comp);
        entityManager.getTransaction().commit();

    } catch (Exception e) {

        log.error("Error in Composer::createComposer( " + name + ") //"
                + e.toString());
        throw e;
    } finally {
        entityManager.close();
    }
    return comp;
}

我发现的一个问题是变量'ServerFailure'只包含failure.message中的信息;所有其他变量都为空。

感谢Piotr的帮助

以下是我最终所做工作的代码:

客户端中的代码

req.fire(new Receiver<ComposerProxy>() {

                        public void onSuccess(ComposerProxy arg0) {

                            ComposerProxy comp;
                            comp = arg0;
                        }

                        public void onFailure(ServerFailure failure) {

                            serverError.getServerError(failure,
                                    "onAddButtonClicked");

                        }

                    });
服务器中的服务

public static Composer createComposer(String name) throws Throwable {
    EntityManager entityManager = entityManager();
    Composer comp = new Composer();

    try {
        comp.setName(name);
        comp.setId(1);

        entityManager.getTransaction().begin();
        entityManager.persist(comp);
        entityManager.getTransaction().commit();

    } catch (Exception e) {

        log.error("Error in Composer::createComposer( " + name + ") //"
                + e.toString());
        throw e;
    } finally {
        entityManager.close();
    }
    return comp;
}
我发现的一个问题是变量'ServerFailure'只包含failure.message中的信息;所有其他变量都为空