没有名为 ws-persist 的 EntityManager 持久性提供程序

发布于 2024-12-14 21:11:29 字数 2041 浏览 1 评论 0原文

我正在构建 JAX-RS Web 服务(泽西岛),现在我尝试开始使用 JPA。我选择了 eclipselink 来管理这种持久性。

首先,我正在编写一些 junit 测试用例,直到弄清楚所有内容如何组合在一起。

在我的 persistence.xml (WEB-INF/persistence.xml) 中,我有:

<?xml version="1.0" encoding="UTF-8" ?>
<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"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="ws-persist" transaction-type="RESOURCE_LOCAL">
    <class>beans.Change</class>
    <properties>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3333/tomcat" />
        <property name="javax.persistence.jdbc.user" value="tomcat" />
        <property name="javax.persistence.jdbc.password" value="...." />
        <property name="eclipselink.ddl-generation" value="create-tables" />
        <property name="eclipselink.ddl-generation.output-mode" value="database" />
    </properties>
</persistence-unit>

在我的测试课上我有。

public class PersistenceTests {

private EntityManager em = null;

@Before
public void setUp() throws Exception {      
    Properties propertiesMap = new Properties();
    propertiesMap.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.DROP_AND_CREATE);

    EntityManagerFactory  factory = Persistence.createEntityManagerFactory("ws-persist", propertiesMap);
    em = factory.createEntityManager();
}

@After
public void tearDown() throws Exception {
}

@Test
public void testSetUp(){
    Assert.assertNotNull("Entity manager was null", em);
    Assert.assertTrue("Entity manager wasn't connected", em.isOpen());
}
}

我的 WEB-INF/lib 文件夹下有 eclipselink.jar 和两个 javax.persistence_*.jar。 我遇到了标题中提到的异常,有人可以帮我弄清楚如何解决这个问题吗?

谢谢。

I'm building a JAX-RS web service (Jersey) and now I'm trying to start using JPA. I have selected eclipselink to manage this persistence.

To start off, I'm writing some junit test cases until I figure out how everything will come together.

In my persistence.xml (WEB-INF/persistence.xml) I have:

<?xml version="1.0" encoding="UTF-8" ?>
<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"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="ws-persist" transaction-type="RESOURCE_LOCAL">
    <class>beans.Change</class>
    <properties>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3333/tomcat" />
        <property name="javax.persistence.jdbc.user" value="tomcat" />
        <property name="javax.persistence.jdbc.password" value="...." />
        <property name="eclipselink.ddl-generation" value="create-tables" />
        <property name="eclipselink.ddl-generation.output-mode" value="database" />
    </properties>
</persistence-unit>

In my test class I have.

public class PersistenceTests {

private EntityManager em = null;

@Before
public void setUp() throws Exception {      
    Properties propertiesMap = new Properties();
    propertiesMap.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.DROP_AND_CREATE);

    EntityManagerFactory  factory = Persistence.createEntityManagerFactory("ws-persist", propertiesMap);
    em = factory.createEntityManager();
}

@After
public void tearDown() throws Exception {
}

@Test
public void testSetUp(){
    Assert.assertNotNull("Entity manager was null", em);
    Assert.assertTrue("Entity manager wasn't connected", em.isOpen());
}
}

I have eclipselink.jar, and two javax.persistence_*.jars under my WEB-INF/lib folder.
I'm getting the exception metioned in the title, can someone please help me figure out how to fix this?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彻夜缠绵 2024-12-21 21:11:29

我会尝试在 persistence.xml 中添加持久性提供程序

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

编辑)或将 persistence.xml 移动到 META-INF 文件夹。对于网络应用程序,这必须位于 WEB-INF/classes 中

I would try to add the persistence provider in the persistence.xml

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

(edit) or moving persistence.xml to META-INF folder. For a web-app this has to be in WEB-INF/classes

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文