没有名为 ws-persist 的 EntityManager 持久性提供程序
我正在构建 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会尝试在 persistence.xml 中添加持久性提供程序
(编辑)或将 persistence.xml 移动到
META-INF
文件夹。对于网络应用程序,这必须位于 WEB-INF/classes 中I would try to add the persistence provider in the persistence.xml
(edit) or moving persistence.xml to
META-INF
folder. For a web-app this has to be inWEB-INF/classes