3 Replies Latest reply on Jun 2, 2016 1:31 AM by haris-khan-laghari

    Getting Invalid persistence.xml Error parsing XML (line-1 : column -1): cvc-elt.1: Cannot find the declaration of element 'persistence'.?

    haris-khan-laghari

      I am sorry since this question will be very descriptive i have tried every thing in my knowledge but the problem presist.

       

      i am trying to call my EJB function which has entity manager factory from  a java file and gets this error.

       

      I have pasted all the necessary files below please point what i am doing wrong.

       

       

      My persistence.xml file



      This file is present in META-INF

       

      <?xml version="1.0" encoding="UTF-8"?>

      <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

        <persistence-unit name="myPU">

        <provider>org.hibernate.ejb.HibernatePersistence</provider>

            <jta-data-source>java:/MyDS</jta-data-source>

            <class>com.employee.model.Employee</class>

            <properties>

            <property name="hibernate.show_sql" value="true" />

            <property name="hibernate.format_sql" value="true" />

            <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />

            <property name="hibernate.hbm2ddl.auto" value="validate" />

           </properties>

        </persistence-unit>

      </persistence>

       

       

       

      My EJB remote class

      @Remote

      public interface ContactDiaryRemote {

        public void helloWorld();

        public List<Employee> findAllEmployees();

      }

       

      My stateless EJB remote class implementatin class

       

      @Stateless

      public class ContactDiary implements ContactDiaryRemote {   

       

        /**

            * Default constructor.

            */

       

          public ContactDiary() {

              // TODO Auto-generated constructor stub

          }

        @Override

        public void helloWorld(){

            System.out.println("Hello World");

      }

        @Override

        public List<Employee> findAllEmployees(){

        EntityManagerFactory emf =Persistence.createEntityManagerFactory("myPU");

        EntityManager em = emf.createEntityManager();

        EntityTransaction et = null;

        List<Employee> employeeList=null;

       

        try{

        if(!em.getTransaction().isActive()){

        em.getTransaction().begin();

        javax.persistence.Query query = em.createQuery("EXEC GetAllEmployee");

        employeeList= query.getResultList();

        System.out.println(employeeList);

        em.close();

        }

       

        }catch(Exception e){

       

        e.printStackTrace();

       

        em.close();

       

        }

        return employeeList;

        }

      }

       

      So up till here every thing looks fine as server don't give any error and deploys the project here is what my console shows:

       

      17:09:25,718 INFO  [org.jboss.modules] JBoss Modules version 1.1.1.GA

      17:09:25,843 INFO  [org.jboss.msc] JBoss MSC version 1.0.2.GA

      17:09:25,874 INFO  [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting

      17:09:26,370 INFO  [org.xnio] XNIO Version 3.0.3.GA

      17:09:26,370 INFO  [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)

      17:09:26,386 INFO  [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA

      17:09:26,386 INFO  [org.jboss.remoting] JBoss Remoting version 3.2.3.GA

      17:09:26,417 INFO  [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers

      17:09:26,464 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 42) JBAS013101: Activating Security Subsystem

      17:09:26,464 INFO  [org.jboss.as.osgi] (ServerService Thread Pool -- 37) JBAS011940: Activating OSGi Subsystem

      17:09:26,433 INFO  [org.jboss.as.connector] (MSC service thread 1-8) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)

      17:09:26,474 INFO  [org.jboss.as.security] (MSC service thread 1-3) JBAS013100: Current PicketBox version=4.0.7.Final

      17:09:26,417 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 29) JBAS010280: Activating Infinispan subsystem.

      17:09:26,489 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 46) JBAS015537: Activating WebServices Extension

      17:09:26,505 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 36) JBAS011800: Activating Naming Subsystem

      17:09:26,505 INFO  [org.jboss.as.naming] (MSC service thread 1-6) JBAS011802: Starting Naming Service

      17:09:26,505 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-6) JBAS015400: Bound mail session [java:jboss/mail/Default]

      17:09:26,536 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 25) JBAS010403: Deploying JDBC-compliant driver class com.microsoft.sqlserver.jdbc.SQLServerDriver (version 2.0)

      17:09:26,583 INFO  [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-3) JBoss Web Services - Stack CXF Server 4.0.2.GA

      17:09:26,677 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-2) Starting Coyote HTTP/1.1 on http-localhost-127.0.0.1-8080

      17:09:26,770 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-1) JBAS015012: Started FileSystemDeploymentService for directory C:\jboss-as-7.1.1\standalone\deployments

      17:09:26,786 INFO  [org.jboss.as.remoting] (MSC service thread 1-8) JBAS017100: Listening on localhost/127.0.0.1:9999

      17:09:26,786 INFO  [org.jboss.as.remoting] (MSC service thread 1-2) JBAS017100: Listening on localhost/127.0.0.1:4447

      17:09:26,786 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015014: Re-attempting failed deployment MyContactDiary.jar

      17:09:26,786 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found MyContactDiary.jar in deployment directory. To trigger deployment create a file called MyContactDiary.jar.dodeploy

      17:09:26,849 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) JBAS010400: Bound data source [java:/MyDS]

      17:09:26,864 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "MyContactDiary.jar"

      17:09:26,927 INFO  [org.jboss.as.jpa] (MSC service thread 1-3) JBAS011401: Read persistence.xml for myPU

      17:09:26,974 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-2) JNDI bindings for session bean named ContactDiary in deployment unit deployment "MyContactDiary.jar" are as follows:

       

       

        java:global/MyContactDiary/ContactDiary!com.myapp.buisness.ContactDiaryRemote

        java:app/MyContactDiary/ContactDiary!com.myapp.buisness.ContactDiaryRemote

        java:module/ContactDiary!com.myapp.buisness.ContactDiaryRemote

        java:jboss/exported/MyContactDiary/ContactDiary!com.myapp.buisness.ContactDiaryRemote

        java:global/MyContactDiary/ContactDiary

        java:app/MyContactDiary/ContactDiary

        java:module/ContactDiary

       

       

      17:09:27,036 INFO  [org.jboss.as.jpa] (MSC service thread 1-1) JBAS011402: Starting Persistence Unit Service 'MyContactDiary.jar#myPU'

      17:09:27,099 INFO  [org.hibernate.annotations.common.Version] (MSC service thread 1-1) HCANN000001: Hibernate Commons Annotations {4.0.1.Final}

      17:09:27,099 INFO  [org.hibernate.Version] (MSC service thread 1-1) HHH000412: Hibernate Core {4.0.1.Final}

      17:09:27,099 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-1) HHH000206: hibernate.properties not found

      17:09:27,099 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-1) HHH000021: Bytecode provider name : javassist

      17:09:27,114 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-1) HHH000204: Processing PersistenceUnitInfo [

        name: myPU

        ...]

      17:09:27,208 INFO  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-1) HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider

      17:09:27,505 INFO  [org.hibernate.dialect.Dialect] (MSC service thread 1-1) HHH000400: Using dialect: org.hibernate.dialect.SQLServerDialect

      17:09:27,519 ERROR [org.jboss.remoting.remote.connection] (Remoting "asd376:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: An established connection was aborted by the software in your host machine

      17:09:27,519 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-1) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory

      17:09:27,535 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-1) HHH000397: Using ASTQueryTranslatorFactory

      17:09:27,566 ERROR [org.jboss.remoting.remote.connection] (Remoting "asd376:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: An established connection was aborted by the software in your host machine

      17:09:27,574 INFO  [org.hibernate.validator.util.Version] (MSC service thread 1-1) Hibernate Validator 4.2.0.Final

      17:09:27,708 INFO  [org.hibernate.tool.hbm2ddl.SchemaValidator] (MSC service thread 1-1) HHH000229: Running schema validator

      17:09:27,708 INFO  [org.hibernate.tool.hbm2ddl.SchemaValidator] (MSC service thread 1-1) HHH000102: Fetching database metadata

      17:09:27,818 INFO  [org.hibernate.tool.hbm2ddl.TableMetadata] (MSC service thread 1-1) HHH000261: Table found: emp.dbo.employee

      17:09:27,818 INFO  [org.hibernate.tool.hbm2ddl.TableMetadata] (MSC service thread 1-1) HHH000037: Columns: [id, lastname, firstname]

      17:09:27,849 INFO  [org.jboss.as] (MSC service thread 1-3) JBAS015951: Admin console listening on http://127.0.0.1:9990

      17:09:27,849 INFO  [org.jboss.as] (MSC service thread 1-3) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 2319ms - Started 172 of 249 services (76 services are passive or on-demand)

      17:09:27,927 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "MyContactDiary.jar"

       

       

       

      My class to use ejb and call/ utilize it's functions

       

       

       

      public class MyDiary {

       

        public static void main(String[] args) {

       

        // TODO Auto-generated method stub

        ContactDiaryRemote diary = doLookUp();

       

      //This EJB call to it's function works as expected

       

       

        diary.helloWorld();

       

       

       

        System.out.println("\n\n------------------------------------\n\n");

       

      //This is where all the issue comes in


        diary.findAllEmployees();

       

        }

       

        private static ContactDiaryRemote doLookUp(){

       

        Context context=null;

       

        ContactDiaryRemote diary =null;

       

        try{

       

        context=ClientUtility.getInitialContext();

       

        String lookUpName = getLookUpName();

       

        System.out.println(context.lookup(lookUpName).toString());

       

        diary = (ContactDiaryRemote) context.lookup(lookUpName);

       

       

       

       

        }catch(NamingException e){

       

        e.printStackTrace();

       

        }

       

       

        return diary;

        }

       

        private static String getLookUpName(){

       

        String appName = "";

       

        String moduleName = "MyContactDiary";

       

        String distinctName = "";

       

        String beanName = ContactDiary.class.getSimpleName();

       

        String interfaceName = ContactDiaryRemote.class.getName();

       

        // Create a look up string name

        String name = "ejb:" + appName + "/" + moduleName + "/" +

        distinctName + "/" + beanName + "!" + interfaceName;

       

        System.out.println(name);

       

        return name;

       

        }

       

       

      }