I have a standalone JavaSE application and java 8.
I use osgi framework and these are the bundles I install:
Code:
<bundle name="hibernate-core-5.1.0.Final.jar"/>
<bundle name="hibernate-jpa-2.1-api-1.0.0.Final.jar"/>
<bundle name="hibernate-entitymanager-5.1.0.Final.jar"/>
This is my persistence.xml file which is located in META-INF folder of my bundle:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="myPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.temp.MyEntity</class>
<properties>
<!-- Configuring JDBC properties -->
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:tcp://localhost//home/data/database"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value=""/>
<!-- Hibernate properties -->
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<!-- Configuring Connection Pool -->
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.max_size" value="20" />
<property name="hibernate.c3p0.timeout" value="500" />
<property name="hibernate.c3p0.max_statements" value="50" />
<property name="hibernate.c3p0.idle_test_period" value="2000" />
</properties>
</persistence-unit>
</persistence>
This is the way I create EntityManagerFactory:
Code:
EntityManagerFactory emf=Persistence.createEntityManagerFactory("myPersistenceUnit");
In my pom I have:
Code:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
</dependency>
And this is what I get
Quote:
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named myPersistenceUnit
How to fix it?
I even tried in karaf:
Code:
feature:install transaction
feature:install jpa
feature:install hibernate
after that I install and start my bundle. The same result.