在 Jetty 中配置 JPA 时出现问题

发布于 2024-08-01 13:29:26 字数 2134 浏览 14 评论 0原文

我正在尝试将 JPA (Toplink) 配置为在从 Maven 插件运行的 Jetty 中运行,并且收到 javax.naming.NameNotFoundException。 具体细节。

web.xml:

<persistence-unit-ref>
    <persistence-unit-ref-name>persistence/mod</persistence-unit-ref-name>
    <persistence-unit-name>ModPU</persistence-unit-name>
</persistence-unit-ref>

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
  <persistence-unit name="ModPU" transaction-type="RESOURCE_LOCAL">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <properties>
      <property name="toplink.jdbc.url" value="jdbc:mysql://localhost/mod"/>
      <property name="toplink.jdbc.user" value="user"/>
      <property name="toplink.jdbc.driver" value="org.gjt.mm.mysql.Driver"/>
      <property name="toplink.jdbc.password" value="pass"/>
      <property name="toplink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

代码:

@PersistenceUnit(unitName = "ModPU")
EntityManagerFactory emf;

引用 emf 时出错:

Caused by: javax.naming.NameNotFoundException; remaining name 'persistence/ugc'
    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:634)
    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:665)
    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:665)
    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:680)
    at org.mortbay.naming.java.javaRootURLContext.lookup(javaRootURLContext.java:112)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.sun.jersey.server.impl.container.servlet.ThreadLocalNamedInvoker.invoke(ThreadLocalNamedInvoker.java:65)
    ... 37 more

I am trying to get JPA (Toplink) configured to run in Jetty being run from the maven plugin and am getting a javax.naming.NameNotFoundException. The specifics.

web.xml:

<persistence-unit-ref>
    <persistence-unit-ref-name>persistence/mod</persistence-unit-ref-name>
    <persistence-unit-name>ModPU</persistence-unit-name>
</persistence-unit-ref>

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
  <persistence-unit name="ModPU" transaction-type="RESOURCE_LOCAL">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <properties>
      <property name="toplink.jdbc.url" value="jdbc:mysql://localhost/mod"/>
      <property name="toplink.jdbc.user" value="user"/>
      <property name="toplink.jdbc.driver" value="org.gjt.mm.mysql.Driver"/>
      <property name="toplink.jdbc.password" value="pass"/>
      <property name="toplink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

code:

@PersistenceUnit(unitName = "ModPU")
EntityManagerFactory emf;

error when referencing emf:

Caused by: javax.naming.NameNotFoundException; remaining name 'persistence/ugc'
    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:634)
    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:665)
    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:665)
    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:680)
    at org.mortbay.naming.java.javaRootURLContext.lookup(javaRootURLContext.java:112)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.sun.jersey.server.impl.container.servlet.ThreadLocalNamedInvoker.invoke(ThreadLocalNamedInvoker.java:65)
    ... 37 more

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

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

发布评论

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

评论(1

ペ泪落弦音 2024-08-08 13:29:26

这一行是不需要的,应该删除。

<persistence-unit-ref-name>persistence/mod</persistence-unit-ref-name>

我相信web.xml 中的

I believe the line:

<persistence-unit-ref-name>persistence/mod</persistence-unit-ref-name>

in your web.xml is not needed and should be removed.

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