persistence.xml中的两个持久性单元 - 一个工作,另一个不工作

时间:2014-08-01 14:03:41

标签: java mysql jpa objectdb

我在java中使用JPA应用程序时遇到了这么奇怪的问题。我正在尝试从MySQL数据库中读取数据并将其写入ObjectDB嵌入数据库,但是当我尝试打开持久性单元时,我收到了此消息:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named itunes_puSQL
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
   at br.com.lagranzotto.itunes.parser.main.iTunesParser.read(iTunesParser.java:78)
   at br.com.lagranzotto.itunes.parser.main.iTunesParser.main(iTunesParser.java:72)

我的persistence.xml如下:

    <persistence-unit name="itunes_pu" transaction-type="RESOURCE_LOCAL">

        <provider>com.objectdb.jpa.Provider</provider>

        <class>br.com.lagranzotto.itunes.parser.model.Album</class>
        <class>br.com.lagranzotto.itunes.parser.model.Artist</class>
        <class>br.com.lagranzotto.itunes.parser.model.Cover</class>
        <class>br.com.lagranzotto.itunes.parser.model.Track</class>

        <properties>
            <property name="javax.persistence.jdbc.url" value="objectdb:itunes.odb"/>
        </properties>

    </persistence-unit>

    <persistence-unit name="itunes_puSQL" transaction-type="RESOURCE_LOCAL">

        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

        <class>br.com.lagranzotto.itunes.parser.model.Album</class>
        <class>br.com.lagranzotto.itunes.parser.model.Artist</class>
        <class>br.com.lagranzotto.itunes.parser.model.Cover</class>
        <class>br.com.lagranzotto.itunes.parser.model.Track</class>

        <properties>
            <property name="eclipselink.jdbc.password" value="**************"/>
            <property name="eclipselink.jdbc.user" value="itunes"/>
            <property name="eclipselink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="eclipselink.jdbc.url" value="jdbc:mysql://localhost:3306/itunes"/>
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
            <property name="eclipselink.logging.level" value="INFO"/>
        </properties>

    </persistence-unit>

</persistence>

每个应用程序不能有多个持久性单元吗?

1 个答案:

答案 0 :(得分:0)

该异常与第一个持久性单元或具有多个持久性单元无关。 JPA支持并允许在一个应用程序中使用多个持久性单元。

错误消息表明JPA找不到可以处理itunes_puSQL持久性单元的持久性提供程序(即JPA实现)。更具体地说,找不到类org.eclipse.persistence.jpa.PersistenceProvider,它是EclipseLink的一部分(在XML中作为提供者指定)。

如上所述,检查您的类路径。确保EclipseLink和ObjectDB都在类路径中。