2010-07-31 56 views
2

我必須對我的一個項目使用JPA項目,但一旦我創建一個EntityManager,在我的SessionBean調用persistencecontect我有此錯誤:問題引用JPA

@Stateless 
public class Biblio implements BiblioLocal { 
@PersistenceContext(unitName="BiblioJPA") 
private EntityManager em; 
    /** 
    * Default constructor. 
    */ 
    public Biblio() { 
     // TODO Auto-generated constructor stub 
    } 

@Override 
public String succes() { 
    // TODO Auto-generated method stub 
    return " beta"; 
} 
public void toevoegenBoek(){ 
    Boeken boek = new Boeken(); 
    boek.setTitel("harry P."); 
    boek.setAuteur("rowling"); 
    em.persist(boek); 
} 

} 

我的servlet(它調用一個來自這個sessionbean的方法)將不會再加載,並給我這個很長的錯誤,我不明白任何東西。有任何想法嗎? (沒有我servlet加載的entitymanager和persistencecontext,但後來我無法調用與jpa相關的任何函數!)

謝謝!

錯誤運行servlet當我得到:

javax.servlet.ServletException: Error instantiating servlet class servlets.BiblioServlet 
    org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190) 
    org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92) 
    org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126) 
    org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70) 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
    org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330) 
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829) 
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598) 
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) 
    java.lang.Thread.run(Unknown Source) 


root cause 

java.lang.RuntimeException: Unable to inject jndi dependency: env/servlets.BiblioServlet/biblio into property servlets.BiblioServlet.biblio: BiblioEAR not bound 
    org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:82) 
    org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99) 
    org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjectors(TomcatInjectionContainer.java:366) 
    org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:271) 
    org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:265) 
    org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:256) 
    org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190) 
    org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92) 
    org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126) 
    org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70) 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
    org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330) 
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829) 
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598) 
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) 
    java.lang.Thread.run(Unknown Source) 


root cause 

javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: BiblioEAR not bound] 
    org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1352) 
    org.jnp.interfaces.NamingContext.lookup(NamingContext.java:817) 
    org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686) 
    org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:44) 
    org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:75) 
    org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99) 
    org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjectors(TomcatInjectionContainer.java:366) 
    org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:271) 
    org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:265) 
    org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:256) 
    org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190) 
    org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92) 
    org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126) 
    org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70) 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
    org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330) 
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829) 
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598) 
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) 
    java.lang.Thread.run(Unknown Source) 


root cause 

javax.naming.NameNotFoundException: BiblioEAR not bound 
    org.jnp.server.NamingServer.getBinding(NamingServer.java:771) 
    org.jnp.server.NamingServer.getBinding(NamingServer.java:779) 
    org.jnp.server.NamingServer.getObject(NamingServer.java:785) 
    org.jnp.server.NamingServer.lookup(NamingServer.java:396) 
    org.jnp.interfaces.NamingContext.lookup(NamingContext.java:726) 
    org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686) 
    javax.naming.InitialContext.lookup(Unknown Source) 
    org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1346) 
    org.jnp.interfaces.NamingContext.lookup(NamingContext.java:817) 
    org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686) 
    org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:44) 
    org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:75) 
    org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99) 
    org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjectors(TomcatInjectionContainer.java:366) 
    org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:271) 
    org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:265) 
    org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:256) 
    org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190) 
    org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92) 
    org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126) 
    org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70) 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
    org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330) 
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829) 
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598) 
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) 
    java.lang.Thread.run(Unknown Source) 

在我的控制檯(在Eclipse)錯誤

DEPLOYMENTS MISSING DEPENDENCIES: 
    Deployment "jboss.j2ee:ear=BiblioEAR.ear,jar=BiblioEJB.jar,name=Biblio,service=EJB3" is missing the following dependencies: 
    Dependency "<UNKNOWN jboss.j2ee:ear=BiblioEAR.ear,jar=BiblioEJB.jar,name=Biblio,service=EJB3>" (should be in state "Described", but is actually in state "** UNRESOLVED Demands 'persistence.unit:unitName=BiblioEAR.ear/BiblioJPA.jar#BiblioJPA' **") 
    Deployment "jboss.j2ee:ear=BiblioEAR.ear,jar=BiblioEJB.jar,name=Biblio,service=EJB3_endpoint" is missing the following dependencies: 
    Dependency "jboss.j2ee:ear=BiblioEAR.ear,jar=BiblioEJB.jar,name=Biblio,service=EJB3" (should be in state "Configured", but is actually in state "PreInstall") 

DEPLOYMENTS IN ERROR: 
    Deployment "persistence.unit:unitName=BiblioEAR.ear/BiblioJPA.jar#BiblioJPA" is in error due to the following reason(s): org.xml.sax.SAXParseException: cvc-complex-type.3.1: Value '2.0' of attribute 'version' of element 'entity-mappings' is not valid with respect to the corresponding attribute use. Attribute 'version' has a fixed value of '1.0'. 
    Deployment "<UNKNOWN jboss.j2ee:ear=BiblioEAR.ear,jar=BiblioEJB.jar,name=Biblio,service=EJB3>" is in error due to the following reason(s): ** UNRESOLVED Demands 'persistence.unit:unitName=BiblioEAR.ear/BiblioJPA.jar#BiblioJPA' ** 

編輯:

的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="BiblioJPA" transaction-type="JTA"> 
     <jta-data-source>java:/MySqlDSAlfa</jta-data-source> 
    </persistence-unit> 
</persistence> 

mysql-ds。 XML

<datasources> 
    <local-tx-datasource> 
    <jndi-name>MySqlDSAlfa</jndi-name> 
    <connection-url>jdbc:mysql://localhost:8080/database</connection-url> 
    <driver-class>com.mysql.jdbc.Driver</driver-class> 
    <user-name>root</user-name> 
    <password></password> 
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name> 
    <metadata> 
     <type-mapping>mySQL</type-mapping> 
    </metadata> 
    </local-tx-datasource> 
</datasources> 

回答

0

我降級到Eclipse伽利略,它開始工作,我不知道究竟是什麼問題,但它已經修復了我。

0

嗯,它看起來像一個JDNI查找問題( 「JPA無法查找數據源」)。

您能否請您出示您的persistence.xml和您的xxx-ds.xml配置文件。


好了,現在,這個錯誤看起來奇怪(從控制檯輸出):

org.xml.sax.SAXParseException: cvc-complex-type.3.1: Value '2.0' of attribute 'version' of element 'entity-mappings' is not valid with respect to the corresponding attribute use. Attribute 'version' has a fixed value of '1.0'.

看來你正在使用對象/關係映射文件和我怕你面對HHH-5310這目前尚未修復。你沒有對象/關係映射文件嗎?

+0

嘿,我覺得真的很愚蠢,但似乎你是對的,我在我的數據庫名稱拼寫錯誤在我的mysql-ds.xml文件。 (它現在已經修復,名稱確實是「數據庫」)但是它仍然無法正常工作,所以我正在更新我的錯誤消息並添加了xml文件。感謝您的幫助! – networkprofile 2010-07-31 00:55:42

+0

@Sled:不客氣。但是你真的更新了錯誤信息嗎? – 2010-07-31 01:09:05

+0

嘿,是的,我做了(這是我目前得到的錯誤和「JPA無法查找數據源」消失了)。我還添加了控制檯錯誤.. – networkprofile 2010-07-31 08:23:16

-1
+0

歡迎來到SO。雖然這是使用超鏈接到其他網站的正確方式,但您至少應該包含在該網站找到的解決方案(如果您願意,可以獲得更少的詳細信息)以及關於網站的一些詳細信息(涉及的內容,解決方案的帖子或評論等等)您可以使用您的文章下方的編輯鏈接對其進行修改並在需要時添加更多信息。我還建議你看看我們的FAQ:http://stackoverflow.com/faq - 祝你好運! – ForceMagic 2012-12-06 01:53:08