11 Replies Latest reply on Jul 28, 2011 11:51 AM by htfv

    Adding a persistence.xml file from another package

    eabohorquezs

      Hello Guys,

       

      Hope you are doing quite well.

      I am new with Arquillian. I will try to be clear to get some help

       

      I have 3 modules into 3 different packages.

       

      A ---|

            |----B

            |----C

       

       

      The package A is just a container for the other 2 packages.

      B is a package of EJBs.

      C is a package which contains POJOS and its persistence.xml file.

       

      Im creating my test cases into

      B ---|

            |---src

                    ---|

                       |---test

                                ---|

                                   |---java

                                            ---|

                                               |---RequestBrokerTestCase.java

       

      My persistence.xml file is into:

      C---|

            |---src

                    ---|

                       |---META-INF

                                ---|

                                   |---persistence.xml


       

      Having run my test case I obtained this error:

       

       

      -------------------------------------------------------------------------------

       

      Test set: test.java.RequestBrokerTestCase

       

      -------------------------------------------------------------------------------

       

      Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 8.265 sec <<< FAILURE!

      test.java.RequestBrokerTestCase  Time elapsed: 0 sec  <<< ERROR!

      org.jboss.arquillian.spi.client.container.DeploymentException: Failed to deploy test.war

          at org.jboss.arquillian.container.jbossas.remote_6.JBossASRemoteContainer.deploy(JBossASRemoteContainer.java:169)

       

      .

      .

      .

          at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

      Caused by: java.lang.RuntimeException: org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

       

      *** DEPLOYMENTS IN ERROR: Name -> Error

       

      vfs:///C:/jboss-6.0.0.Final/server/default/deploy/test.war -> org.jboss.deployers.spi.DeploymentException: Error deploying test.war: Exception while processing container metadata for EJB: CardsControlNoRefManager in unit: test.war

       

      DEPLOYMENTS IN ERROR:

       

        Deployment "vfs:///C:/jboss-6.0.0.Final/server/default/deploy/test.war" is in error due to the following reason(s): java.lang.IllegalArgumentException: Can't find a persistence unit named 'TransactionalCorePersistancePU' in AbstractVFSDeploymentContext@3691798{vfs:///C:/jboss-6.0.0.Final/server/default/deploy/test.war}

       

       

      TransactionalCorePersistancePU is defined into the persitence.xml file as follows:

      .

      .

      .

      <persistence-unit name="TransactionalCorePersistancePU" transaction-type="JTA">

      .

      .

      .

       

      How can I add this persistence.xml file to my test case deployment run into B?

       

      or what package should I place my test cases in? 

       

      Thanks in advance for your help.

        • 1. Re: Adding a persistence.xml file from another package
          aslak

          As long as there is only 1 META-INF/persistence.xml on classpath, this should work:

           

          addAsManifestResource("META-INF/persistence.xml", "persistence.xml")

           

          The String as a first argument will be interpited as a ClassLoader Resource.

          • 2. Re: Adding a persistence.xml file from another package
            aslak

            If you have multiple persistence.xml on cp from multiple modules, e.g. C and D. Then there is currently no way to specify that you want the one from D instead of C. This is defined based on the order of the modules in ClassPath I believe.

             

            This could be a useful feature, please create a feature request at https://issues.jboss.org/browse/SHRINKWRAP if you want to..

            • 3. Re: Adding a persistence.xml file from another package
              eabohorquezs

              Hello mate,

              Thanks to answer my question.


              I tried your advice and other 2 things that I thought could work; I will show you these 3 createTestArchive methods below:

               

              1) Your advice:

              @Deployment

                 public static Archive<?> createTestArchive()

                 {

                      return ShrinkWrap.create(WebArchive.class, "test.war")

                     .addPackage(RequestBroker.class.getPackage())

                     .     

                     //I add all the packages and classes in here. And finally...

                     .

                     .addAsManifestResource("META-INF/persistence.xml", "persistence.xml");

                 }

               

              2) My option 1:

              I placed the C.jar which contains the persistence.xml into B package (src/test/resources)

                

              @Deployment

                 public static Archive<?> createTestArchive()

                 {

                     WebArchive deployment = ShrinkWrap.create(WebArchive.class, "test.war")

                     .addPackage(RequestBroker.class.getPackage())

                     .

                     //I add all the packages and classes in here.

               

               

                     WebArchive imported = ShrinkWrap.create(WebArchive.class, "test2.war")

                     .addAsLibrary(new File("target/test-classes/C.jar"));

               

               

                     deployment.merge(imported);

                     return deployment;

                 }

               

              3) My option 2:


              @Deployment

                 public static Archive<?> createTestArchive()

                 {

                     return ShrinkWrap.create(WebArchive.class, "test.war")

                     .addPackage(RequestBroker.class.getPackage())

                     .

                     .addAsLibrary(new File("target/test-classes/TransactionalCorePersistance.jar"))



               

              In all cases i got this error;


              -------------------------------------------------------------------------------

              Test set: test.java.RequestBrokerTestCase

              -------------------------------------------------------------------------------

              Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 4.593 sec <<< FAILURE!

              test.java.RequestBrokerTestCase  Time elapsed: 0 sec  <<< ERROR!

              org.jboss.arquillian.spi.client.container.DeploymentException: Failed to deploy test.war

                  at org.jboss.arquillian.container.jbossas.remote_6.JBossASRemoteContainer.deploy(JBossASRemoteContainer.java:169)

              .

              .

              .

              Caused by: java.lang.RuntimeException: org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

               

              *** DEPLOYMENTS IN ERROR: Name -> Error

               

              vfs:///C:/jboss-6.0.0.Final/server/default/deploy/test.war -> org.jboss.deployers.spi.DeploymentException: Error deploying test.war: Exception while processing container metadata for EJB: CardsControlNoRefManager in unit: test.war

               

               

              DEPLOYMENTS IN ERROR:

              Deployment "vfs:///C:/jboss-6.0.0.Final/server/default/deploy/test.war" is in error due to the following reason(s): java.lang.IllegalArgumentException: Can't find a persistence unit named 'TransactionalCorePersistancePU' in AbstractVFSDeploymentContext@24358278{vfs:///C:/jboss-6.0.0.Final/server/default/deploy/test.war}

              .

              .

              .

               

              What do you think about it?


              Thanks

              • 4. Re: Adding a persistence.xml file from another package
                aslak

                For option 1, since your using a WebArchive, you need to use addAsWebInfResource("META-INF/persistence.xml", "META-INF/persistence.xml")

                 

                addAsManifestResource mappes to /META-INF while addAsResource mapps to /WEB-INF/classes (+ the second argument "META-INF/persistence.xml")

                • 5. Re: Adding a persistence.xml file from another package
                  eabohorquezs

                  Aslak...

                  Thanks a lot for your timely help.

                   

                  I followed your recommendation of using addAsWebInfResource("META-INF/persistence.xml", "META-INF/persistence.xml") and fortunately the error changed completely (I was going mad receiving the same error trying different strategies!)

                   

                  Now, I obtained this error which shows that there are missing dependencies and deployments in error.

                  I have attached just some lines:

                  -------------------------------------------------------------------------------

                  Test set: test.java.RequestBrokerTestCase

                  -------------------------------------------------------------------------------

                  Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 15.25 sec <<< FAILURE!

                  test.java.RequestBrokerTestCase  Time elapsed: 0 sec  <<< ERROR!

                  org.jboss.arquillian.spi.client.container.DeploymentException: Failed to deploy test.war

                      at org.jboss.arquillian.container.jbossas.remote_6.JBossASRemoteContainer.deploy(JBossASRemoteContainer.java:169)

                  .

                  .

                  .

                  Caused by: java.lang.RuntimeException: org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

                   

                  DEPLOYMENTS MISSING DEPENDENCIES:

                  Deployment "jboss-switchboard:appName=test,module=test" is missing the following dependencies:

                      Dependency "jboss.j2ee:jar=test.war,name=ExpressionMappingManager,service=EJB3" (should be in state "Installed", but is actually in state "PreInstall")

                  .

                  .

                    Deployment "jboss.ejb3:application=test,module=test,component=MerchantManager,service=EJBBinder" is missing the following dependencies:

                      Dependency "jboss.ejb3:application=test,component=MerchantManager,module=test,service=SessionBeanTypeWrapper" (should be in state "Installed", but is actually in state "**ERROR**")

                  .

                  .

                  Deployment "jboss.j2ee:jar=test.war,name=TransactionsRecIdRefManager,service=EJB3" is missing the following dependencies:

                      Dependency "<UNKNOWN jboss.j2ee:jar=test.war,name=TransactionsRecIdRefManager,service=EJB3>" (should be in state "Installed", but is actually in state "** UNRESOLVED Demands 'persistence.unit:unitName=test.war#TransactionalCorePersistancePU' **")

                  .

                  .

                  DEPLOYMENTS IN ERROR:

                    Deployment "<UNKNOWN jboss.j2ee:jar=test.war,name=StateManager,service=EJB3>" is in error due to the following reason(s): ** UNRESOLVED Demands 'persistence.unit:unitName=test.war#TransactionalCorePersistancePU' **

                  .

                  .

                    Deployment "jboss.ejb3:application=test,module=test,component=TerminalLimitsManager,service=SessionBeanTypeWrapper" is in error due to the following reason(s): java.util.MissingResourceException: Can't find bundle for base name net.emida.transactionalcore.ejb.manager.querys, locale en_US

                  .

                  .

                  I used .addPackage(DirectMappingManager.class.getPackage()) to add the package which contains the classes with troubles.


                  Aslak: any idea about whats happeging? I do not know why the persistence unit is still not resolved...

                   


                  • 6. Re: Adding a persistence.xml file from another package
                    eabohorquezs

                    Also I had not put my data source file into the jboss (JBOSS-HOME/server/default/deploy). It is already placed in that location.

                    • 7. Re: Adding a persistence.xml file from another package
                      aslak

                      can you add this line before you return the archive in the @Deployment method:

                       

                      System.out.println(war.toString(Formatters.VERBOSE))

                      • 8. Re: Adding a persistence.xml file from another package
                        eabohorquezs

                        i will show you lines which includes the classes that i used as example:

                         

                        System.out.println(war.toString(Formatters.VERBOSE)) produced:

                         

                        /WEB-INF/META-INF/persistence.xml

                        .

                        /WEB-INF/classes/net/emida/transactionalcore/ejb/manager/ExpressionMappingManager.class

                        .

                        /WEB-INF/classes/net/emida/transactionalcore/ejb/manager/TransactionsRecIdRefManager.class

                        .

                        /WEB-INF/classes/net/emida/transactionalcore/ejb/manager/StateManager.class

                         

                        As you can see the persistence.xml is correctly deployed.

                        .

                        • 9. Re: Adding a persistence.xml file from another package
                          aslak

                          andres bohorquez wrote:

                           

                          i will show you lines which includes the classes that i used as example:

                           

                          System.out.println(war.toString(Formatters.VERBOSE)) produced:

                           

                          /WEB-INF/META-INF/persistence.xml

                           

                          That should be

                           

                          /WEB-INF/classes/META-INF/persistence.xml

                          • 10. Re: Adding a persistence.xml file from another package
                            eabohorquezs

                            After changing the soruce code through your advice, the error continued appearing. Consequently, I add every class of all my projects to my deployment.

                            Then, a new error appeared something about that the deployment was already registered, so I deleted /data, /log, /tmp, /work folders from
                            JBOSS-HOME/server/default.

                             

                            Now I am getting this:

                            DEPLOYMENTS IN ERROR:

                              Deployment "vfs:///C:/jboss-6.0.0.Final/server/default/deploy/test.war" is in error due to the following reason(s): java.lang.RuntimeException: Could not resolve @EJB reference: [EJB Reference: beanInterface 'net.emida.transactionalcore.ejb.broker.RequestBroker', beanName 'null', mappedName 'null', lookupName 'null', owning unit 'AbstractVFSDeploymentContext@18472036{vfs:///C:/jboss-6.0.0.Final/server/default/deploy/test.war}'] for environment entry: env/test.java.RequestBrokerTestCase/rb in unit AbstractVFSDeploymentContext@18472036{vfs:///C:/jboss-6.0.0.Final/server/default/deploy/test.war}

                             

                            Addionatilly, this is a jboss log piece (to summarise):

                            .

                            .

                            15:24:07,037 INFO  [org.hibernate.ejb.Ejb3Configuration] Processing PersistenceUnitInfo [

                                name: timerdb

                                ...]

                            15:24:07,068 WARN  [org.hibernate.ejb.Ejb3Configuration] Persistence provider caller does not implement the EJB3 spec correctly.PersistenceUnitInfo.getNewTempClassLoader() is null.

                            .

                            .

                            15:24:08,865 WARN  [org.jboss.deployment.MappedReferenceMetaDataResolverDeployer] Unresolved references exist in JBossWebMetaData:[#web-app:AnnotatedEJBReferenceMetaData{name=test.java.RequestBrokerTestCase/rb,ejb-ref-type=null,link=null,ignore-dependecy=false,mapped/jndi-name=null,resolved-jndi-name=null,beanInterface=class net.emida.transactionalcore.ejb.broker.RequestBroker},#web-app:AnnotatedEJBReferenceMetaData{name=test.java.RequestBrokerTestCase/request,ejb-ref-type=null,link=null,ignore-dependecy=false,mapped/jndi-name=null,resolved-jndi-name=null,beanInterface=class net.emida.transactionalcore.client.vo.TopUpRequest}]

                            .

                            .

                            15:45:16,147 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Real: name=vfs:///C:/jboss-6.0.0.Final/server/default/deploy/test.war state=PreReal mode=Manual requiredState=Real: org.jboss.deployers.spi.DeploymentException: Error during deploy: vfs:///C:/jboss-6.0.0.Final/server/default/deploy/test.war

                                at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49) [:2.2.0.GA]

                                at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:185) [:2.2.0.GA]

                                at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1832) [:2.2.0.GA]

                            .

                            .

                            This is my test:

                            @EJB

                            private RequestBroker rb;

                             

                            @EJB

                            private TopUpRequest request;

                             

                            @Test

                            public void isTypedRequest()

                            {

                                 rb = new RequestBroker();

                                 request = new TopUpRequest();

                                 Assert.assertEquals(rb.isTypedRequest(request), true);

                            }

                             

                            I am running my jboss in the same PC of maven. According to examples, people always uses the bean instead of interfaces.

                            • 11. Re: Adding a persistence.xml file from another package
                              htfv

                              It should be addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml"), not addAsWebInfResource.