GWT与JPA - 没有持久性提供者 [英] GWT with JPA - no persistence provider

查看:100
本文介绍了GWT与JPA - 没有持久性提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JPA的GWT



在我的eclipse工作区中有两个项目,我们将它们命名为:

- JPAProject
-GWTP项目



JPAProject包含JPA配置的东西(persistence.xml,实体类等等)。 GWTProject是一个示例GWT项目(取自官方的GWT教程)。


这两个项目都能很好地工作。也就是说,我可以在JPAProject中创建EMF(EntityManagerFactory)并从数据库中获取实体。 GWTProject工作正常,我可以运行它,填充浏览器中的字段文本并获得响应。



我的目标是从GWTProject调用JPAProject来获取实体。但问题是调用DAO时,出现以下异常:

  [WARN] Server class'com.emergit.service .dao.profile.ProfileDaoService'在Web应用程序中找不到,但在系统类路径中找到
[WARN]添加类路径条目'file:/ home / maliniak / workspace / emergit / build / classes /'到此会话的Web应用程序类路径

[WARN] / gwttest / greet
javax.persistence.PersistenceException:否EntityManager的持久性提供程序,名为emergitPU
,位于javax.persistence.Persistence .createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at com.emergit.service.dao.profile.JpaProfileDaoService。< init>(JpaProfileDaoService.java:19)
at pl.maliniak.server.GreetingServiceImpl。< init>(GreetingServiceImpl.java:21)
...
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java: 380)
在org。
at org.mortbay.thread.QueuedThreadPool $ PoolThread.run(QueuedThreadPool.java:488)
[错误] 500 - 开机自检/ gwttest / greet(127.0.0.1)3812字节

我猜可以忽略开头的警告目前。

你有什么想法吗?我想我错过了一些基本观点。所有提示都受到高度赞赏。




更新:我的持久性提供者定义良好,项目本身运作良好。



我想这也是类路径相关的问题。运行GWT项目时,在 WEB-INF / lib 中只有 gwt-servlet.jar

你认为使用自定义Ant文件来构建整个事物是唯一的解决方案(即,将JPA项目制作成jar并将其复制到 WEB-INF / lib中)?或者是否有任何Eclipse解决方案,所以我可以正确设置GWT项目属性,以便GWT项目知道包含 persistence.xml 文件?



更新: OK,我知道了。我试图把persitence.xml放在war / WEB-INF的任何地方,但是一直存在'没有持久性提供者'的错误。事实证明,这不是关于persistence.xml。我没有将eclipselink jar复制到WEB-INF / lib中,因此无法找到在persistence.xml中定义的提供程序类。复制所有罐子做了这件事。



非常感谢Pascal。

解决方案

使用相同的错误消息挣扎了很多,我解决了复制所有jar的问题(eclipselink.jar,eclipselink-jpa -modelgen_2.1.0.v20100614-r7608.jar,javax.persistence_1.0.0.jar,javax.persistence_2.0.1.v201006031150.jar)从EclipseLink zip拖动到我的GWT的... / war / WEB-INF / lib文件夹项目在托管模式下为Jetty提供一切可用服务。
从文件列表中可以看出,我使用的是EclipseLink 2.1。如果有必要,请将此列表调整为您的JPA实现。



希望这可以帮助您。


GWT with JPA

There are two projects in my eclipse workspace, let's name them:

-JPAProject -GWTProject

JPAProject contains JPA configuration stuff (persistence.xml, entity classes and so on). GWTProject is an examplary GWT project (taken from official GWT tutorial).

Both projects work fine alone. That is, I can create EMF (EntityManagerFactory) in JPAProject and get entities from the database. GWTProject works fine too, I can run it, fill the field text in the browser and get the response.

My goal is to call JPAProject from GWTProject to get entities. But the problem is that when calling DAO, I get the following exception:

[WARN] Server class 'com.emergit.service.dao.profile.ProfileDaoService' could not be found in the web app, but was found on the system classpath
[WARN] Adding classpath entry 'file:/home/maliniak/workspace/emergit/build/classes/' to the web app classpath for this session

[WARN] /gwttest/greet
javax.persistence.PersistenceException: No Persistence provider for EntityManager named emergitPU
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
    at com.emergit.service.dao.profile.JpaProfileDaoService.<init>(JpaProfileDaoService.java:19)
    at pl.maliniak.server.GreetingServiceImpl.<init>(GreetingServiceImpl.java:21)  
    ...
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
[ERROR] 500 - POST /gwttest/greet (127.0.0.1) 3812 bytes

I guess that the warnings at the beginning can be omitted for now.

Do you have any ideas? I guess I am missing some basic point. All hints are highly appreciated.


Update: My persistence provider is well defined, the JPA project works well by itself.

I guess it's classpath related problem too. When running the GWT project, in WEB-INF/lib there is only gwt-servlet.jar.

Do you think that making custom Ant file to build whole thing up is the only solution (i.e. make jar out of the JPA project and copying it to WEB-INF/lib)? Or is there any Eclipse solution, so I could set the GWT project properties properly so GWT project would know to include persistence.xml file?

Update: OK, I got it working. I tried to put persitence.xml everywhere in war/WEB-INF where it was possible, but kept getting 'no persistence provider' error. It turned out that it wasn't about persistence.xml. I didn't copy the eclipselink jar to WEB-INF/lib, so it couldn't find provider class defined in persistence.xml. Copying all the jars did the thing.

Thank you very much Pascal.

解决方案

Struggling a lot with the same error message, I solved the problem with copying all jars (eclipselink.jar, eclipselink-jpa-modelgen_2.1.0.v20100614-r7608.jar, javax.persistence_1.0.0.jar, javax.persistence_2.0.1.v201006031150.jar) from the EclipseLink zip to the .../war/WEB-INF/lib folder of my GWT project to make everything available for the Jetty in hosted mode. As you can see from the list of files, I was using EclipseLink 2.1. Please adapt this list to your JPA implementation, if necessary.

Hoping, that this may help you as well.

这篇关于GWT与JPA - 没有持久性提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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