ClassCastException 与 jetty 和 jpa

发布于 2024-10-03 03:02:57 字数 2035 浏览 3 评论 0原文

当我尝试在 jetty(7.2.0 或 8.0.0.M1)上执行基于 jersey、guice 和 jpa 的应用程序时,即使我不使用 JNDI,也会收到以下错误。

    java.lang.ClassCastException: org.eclipse.jetty.jndi.NamingContext cannot be cast to javax.sql.DataSource

Caused by:

javax.persistence.PersistenceException: java.lang.ClassCastException: org.eclipse.jetty.jndi.NamingContext cannot be cast to javax.sql.DataSource
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:397)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:151)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:207)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:195)
...

这是相应的 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="myproject" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:mydb;create=true"/>
      <property name="javax.persistence.jdbc.password" value=""/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
      <property name="javax.persistence.jdbc.user" value=""/>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    </properties>
    <non-jta-data-source/>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
  </persistence-unit>
</persistence>

有什么想法吗?

When I try to execute my application based on jersey, guice, and jpa on jetty (7.2.0 or 8.0.0.M1) I get the following error, even if I don't use JNDI.

    java.lang.ClassCastException: org.eclipse.jetty.jndi.NamingContext cannot be cast to javax.sql.DataSource

Caused by:

javax.persistence.PersistenceException: java.lang.ClassCastException: org.eclipse.jetty.jndi.NamingContext cannot be cast to javax.sql.DataSource
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:397)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:151)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:207)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:195)
...

Here is the corresponding 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="myproject" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:mydb;create=true"/>
      <property name="javax.persistence.jdbc.password" value=""/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
      <property name="javax.persistence.jdbc.user" value=""/>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    </properties>
    <non-jta-data-source/>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
  </persistence-unit>
</persistence>

Any ideas?

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

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

发布评论

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

评论(1

猛虎独行 2024-10-10 03:02:57

您不需要 因为您不使用 JNDI。

You don't need <non-jta-data-source/> since you don't use JNDI.

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