开发者

problem referencing JPA

开发者 https://www.devze.com 2023-01-09 21:15 出处:网络
I have to use a jpa project on one of my projects, but I\'m having this error once I create an entitymanager and call persistencecontect in my sessionbean:

I have to use a jpa project on one of my projects, but I'm having this error once I create an entitymanager and call persistencecontect in my sessionbean:

@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);
 }

}

My servlet (which calls a method from this sessionbean) won't load anymore and gives me this very long error of which i don't understand anything. Any ideas? (without the entitymanager and persistencecontext my servlet does load, but then i'm not able to call any functions related to the jpa!)

Thanks!

The error i get when running the 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.jbos开发者_开发知识库s.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)

The error in my console (in 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' **

Edit:

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>


Well, it looks like a JDNI lookup problem ("JPA is not able to lookup the datasource").

Could you please show your persistence.xml and your xxx-ds.xml configuration files.


Ok, now, this error looks weird (from the console output):

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'.

It seems you are using Object/relational Mapping Files and I'm afraid you're facing HHH-5310 which is currently not fixed. Can you do without Object/relational Mapping Files?


I downgraded to Eclipse galileo and it started working, I don't know what exactly the problem was, but that fixed it for me.


http://opensource.atlassian.com/projects/hibernate/browse/HHH-5310

0

精彩评论

暂无评论...
验证码 换一张
取 消