2010-11-17 39 views
0

當我嘗試在jetty(7.2.0或8.0.0.M1)上基於jersey,guice和jpa執行我的應用程序時,即使我不使用JNDI,也會收到以下錯誤。使用jetty和jpa的ClassCastException

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> 

任何想法對應?

回答

1

由於您不使用JNDI,因此不需要<non-jta-data-source/>

+0

非常感謝! – deamon 2010-11-17 13:29:42