1

I'm having such a strange problem with an JPA application in java. I'm trying to read data from a MySQL database and write it on a ObjectDB embed database but when i try to open the Persistence unit i got this message:

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)

My persistence.xml as follows:

    <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>

I can't have more than one persistence unit per application?

fabian
  • 80,457
  • 12
  • 86
  • 114
lagranzotto
  • 327
  • 1
  • 5
  • 16
  • Yes, you can. The problem lies somewhere else. Could you show your code which instantiate EntityManager? There may be a conflict because of two different persistence providers. – MD Sayem Ahmed Aug 01 '14 at 14:09
  • Also check that eclipselink is on your classpath. – starf Aug 01 '14 at 14:10

1 Answers1

0

The exception is not related to the first persistence unit or for having more than one persistence unit. Using multiple persistence units in one application is supported and allowed by JPA.

The error message indicates that JPA cannot find a persistence provider (i.e. a JPA implementation) that can handle the itunes_puSQL persistence unit. More specifically, class org.eclipse.persistence.jpa.PersistenceProvider, which is part of EclipseLink (and specified in your XML as the provider) is not found.

As suggested above, check your classpath. Make sure that both EclipseLink and ObjectDB are in the classpath.

ObjectDB
  • 1,312
  • 8
  • 9