小编Dmi*_*lev的帖子

OSGi + JPA(postgresql)

我试图在OSGi中使用JPA并遇到这个异常:

 javax.persistence.PersistenceException: No Persistence provider for EntityManager named test 
Run Code Online (Sandbox Code Playgroud)

在META-INF中有简单的实体类,文件"persistence.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="test" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>org.test.Room</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/test"/>
      <property name="javax.persistence.jdbc.password" value="12345"/>
      <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
      <property name="javax.persistence.jdbc.user" value="postgres"/>

    </properties>
  </persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)

激活:

package org.test;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {

    private static BundleContext context;
    static BundleContext getContext() {
        return context;
    }

    public void start(BundleContext bundleContext) throws Exception {
        Activator.context = bundleContext; …
Run Code Online (Sandbox Code Playgroud)

postgresql osgi jpa eclipselink

7
推荐指数
1
解决办法
3133
查看次数

标签 统计

eclipselink ×1

jpa ×1

osgi ×1

postgresql ×1