我创建了支持 JPA 2.0 的 OSGI 捆绑项目。我使用 OpenJpa 作为 JPA 提供程序。当我运行捆绑包时,我无法创建 OpenJPAEntityManagerFactory。请完善我用来创建 OpenJPAEntityManagerFactory 的代码。
OpenJPAEntityManagerFactory emf = OpenJPAPersistence.createEntityManagerFactory(
"StudentServiceProvider",
"META-INF/persistence.xml");
持久性.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="StudentServiceProvider">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>com.student.serviceprovider.model.Student</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/NYL" />
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
<property name="openjpa.ConnectionUserName" value="root" />
<property name="openjpa.ConnectionPassword" value="root" />
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
<property name="openjpa.RuntimeUnenhancedClasses" value="supported" />
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
<!-- To avoid foreign key issues -->
<property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)" />
<!-- Auto create tables -->
<property name="jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
</properties>
</persistence-unit>
</persistence>
在 src 文件夹中,我有 META-INF,并在其中创建了 persistence.xml(META-INF/persistennce.xml)。
请让我知道以解决此问题。