EclipseLink:没有EntityManager的持久性提供程序

时间:2012-03-10 20:26:47

标签: jpa eclipse-plugin playframework eclipselink

我正在尝试开发一个Web应用程序。我开始制作一个Play! Eclipse中的框架项目。 对于模型部分,我选择使用JPA,因为我已经创建了数据库,所以我正在搜索自动生成模型类的方法。 我将其转换为分面形式,并使用Dali创建与数据库的映射。在配置期间,我被要求选择JPA实现,因此我选择了EclipseLink 2.1.3 Helios作为用户库。 我项目中添加的所有罐子。 在搜索类似错误后,我将persistence.xml修改为:

    <?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="StudentApplication">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>models.Grade</class>
        <class>models.GradePK</class>
        <class>models.Student</class>
                <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/studentapplication"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="root"/>
        </properties>
    </persistence-unit>
</persistence>

我现在得到的确切错误是: 执行异常(在第98行的/app/controllers/class.java中) 发生PersistenceException:没有名为jpa的EntityManager的持久性提供程序

我必须注意,在application.conf中我已经声明了数据库连接,当我运行应用程序时,我得到了

  

22:03:53,084 INFO~连接到jdbc:mysql:// localhost / studentapplication?useUnicode = yes&amp; characterEncoding = UTF-8&amp; connectionCollat​​ion = utf8_general_ci

最后文件结构是:

-controllers
 -models
 -views
 -META-INF
          | _persistense.xml

您可能已经理解(除了我的代表)我是Web应用程序开发的新手,特别是JPA。我会非常感激任何帮助。如果我发布了不需要的信息或错过了必填信息,我会提前道歉。谢谢你的时间。

托马斯

1 个答案:

答案 0 :(得分:4)

您似乎使用与 persistence.xml 不同的名称引用应用程序中的持久性单元。您的持久性单元在 persistence.xml 中命名为“StudentApplication”。但是,该错误表明它在您的应用程序中名为“jpa”。

假设您使用的是应用程序管理的实体管理器,那么您的应用中必须有这样的一行:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa");

将其更改为

EntityManagerFactory emf = Persistence.createEntityManagerFactory("StudentApplication");