0

I have the following persistence.xml in META-INF folder of my application:

<?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="Hello" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <properties>
            <property name="hibernate.show_sql" value="true" />
            <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@my.db.com:1521:TEST"/>
            <property name="javax.persistence.jdbc.user" value="newuser" />
            <property name="javax.persistence.jdbc.password" value="password@123" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
        </properties>
    </persistence-unit>
</persistence>

The context-param of web.xml is:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/applicationContext.xml
        /WEB-INF/rules-*.xml
    </param-value>
</context-param>

In the code, I am doing the following:

EntityManagerFactory emf = Persistence
        .createEntityManagerFactory("Hello");
EntityManager em = emf.createEntityManager();
RulesMasterTable rule = em.find(RulesMasterTable.class,
        ruleName);

But the exception is:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named Hello javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)

Why isn't my persistence-unit registered?

1 Answers1

1

I dont think you should use RESOURCE_LOCAL transaction type, go with JTA. Try looking here: Difference between a "jta-datasource" and a " resource-local " datasource?

Community
  • 1
  • 1
awb
  • 324
  • 2
  • 9
  • Well still, you should really consider using `RESOURCE_LOCAL` transaction type. – awb Aug 12 '13 at 12:12