引用JPA的问题

时间:2010-07-31 00:23:38

标签: java eclipse jboss orm

我必须在我的一个项目上使用jpa项目,但是一旦我创建了一个实体管理器并在我的sessionbean中调用persistencecontect,我就会遇到这个错误:

@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调用一个方法)将不再加载并给我这个很长的错误,我什么都不懂。有任何想法吗? (没有entitymanager和persistencecontext我的servlet加载,但是我无法调用任何与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>

3 个答案:

答案 0 :(得分:0)

好吧,它看起来像是一个JDNI查找问题(“JPA无法查找数据源”)。

是否可以显示您的persistence.xmlxxx-ds.xml配置文件。


好的,现在,这个错误看起来很奇怪(来自控制台输出):

  

org.xml.sax.SAXParseException:cvc-complex-type.3.1:元素'entity-mappings'的属性'version'的值'2.0'对于相应的属性使用无效。属性“version”的固定值为“1.0”。

您似乎正在使用对象/关系映射文件,我担心您面临的HHH-5310目前尚未修复。你能不用对象/关系映射文件吗?

答案 1 :(得分:0)

我降级到Eclipse galileo并且它开始工作,我不知道究竟是什么问题,但是这对我来说是固定的。

答案 2 :(得分:-1)