5 Replies Latest reply on Jul 31, 2011 4:57 PM by mcgin

    Resource not found using Embedded Glassfish 3.1

    mcgin

      I'm trying to use Arquillian to test my JPA efforts.  I'm a bit stumped at the moment.  It would appear the JDBC resources are not deploying from the glassfish-resources.xml file as I'm getting a resource not found error.  I've included all the relevant info below.  Any help would be greatly appreciated.

       

      Maven output from test phase:

       

      {code}-------------------------------------------------------

       

      T E S T S

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

      Running com.gamblerstools.betbot.model.PublisherTestCase

      31-Jul-2011 10:05:33 org.jboss.arquillian.impl.client.container.ContainerRegistryCreator getActivatedConfiguration

      INFO: Could not read active container configuration: null

      31-Jul-2011 10:05:35 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient

      INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.

      31-Jul-2011 10:05:35 org.hibernate.validator.util.Version <clinit>

      INFO: Hibernate Validator null

      31-Jul-2011 10:05:35 org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA

      INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.

      31-Jul-2011 10:05:35 com.sun.enterprise.v3.services.impl.GrizzlyService createNetworkProxy

      INFO: Network listener https-listener on port 0 disabled per domain.xml

      31-Jul-2011 10:05:36 com.sun.enterprise.v3.services.impl.GrizzlyProxy$2$1 onReady

      INFO: Grizzly Framework 1.9.31 started in: 135ms - bound to [0.0.0.0:8181]

      31-Jul-2011 10:05:36 com.sun.enterprise.v3.server.AppServerStartup run

      INFO: GlassFish Server Open Source Edition 3.1-b41 (java_re-private) startup time : Embedded (1,141ms), startup services(639ms), total(1,780ms)

      31-Jul-2011 10:05:36 org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread run

      INFO: JMXStartupService: JMXConnector system is disabled, skipping.

      31-Jul-2011 10:05:39 com.sun.enterprise.security.SecurityLifecycle <init>

      INFO: SEC1002: Security Manager is OFF.

      31-Jul-2011 10:05:40 com.sun.enterprise.security.SecurityLifecycle onInitialization

      INFO: SEC1010: Entering Security Startup Service

      31-Jul-2011 10:05:40 com.sun.enterprise.security.PolicyLoader loadPolicy

      INFO: SEC1143: Loading policy provider com.sun.enterprise.security.jacc.provider.SimplePolicyProvider.

      31-Jul-2011 10:05:40 com.sun.enterprise.security.auth.realm.Realm doInstantiate

      INFO: SEC1115: Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.

      31-Jul-2011 10:05:40 com.sun.enterprise.security.auth.realm.Realm doInstantiate

      INFO: SEC1115: Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.

      31-Jul-2011 10:05:40 com.sun.enterprise.security.auth.realm.Realm doInstantiate

      INFO: SEC1115: Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.

      31-Jul-2011 10:05:40 com.sun.enterprise.security.SecurityLifecycle onInitialization

      INFO: SEC1011: Security Service(s) Started Successfully

      31-Jul-2011 10:05:40 com.sun.enterprise.web.WebContainer createHttpListener

      INFO: WEB0169: Created HTTP listener [http-listener] on host/port [0.0.0.0:8181]

      31-Jul-2011 10:05:40 com.sun.enterprise.web.WebContainer createHosts

      INFO: WEB0171: Created virtual server [server]

      31-Jul-2011 10:05:41 com.sun.enterprise.web.WebContainer loadSystemDefaultWebModules

      INFO: WEB0172: Virtual server [server] loaded default web module []

      31-Jul-2011 10:05:42 org.glassfish.api.ActionReport failure

      SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method

      31-Jul-2011 10:05:42 org.glassfish.api.ActionReport failure

      SEVERE: Exception while preparing the app

      31-Jul-2011 10:05:42 com.sun.enterprise.v3.server.ApplicationLifecycle deploy

      SEVERE: Invalid resource : { ResourceInfo : (jndiName=java:app/jdbc/betbot__pm), (applicationName=test) }

      java.lang.RuntimeException: Invalid resource : { ResourceInfo : (jndiName=java:app/jdbc/betbot__pm), (applicationName=test) }

      {code}

       

       

      arquillian.xml

       

      {code:xml}<?xml version="1.0" encoding="UTF-8"?>

      <arquillian xmlns="http://www.jboss.org/arquillian-1.0"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="

            http://www.jboss.org/arquillian-1.0

            http://www.jboss.org/schema/arquillian/arquillian-1.0.xsd" >

          <container qualifier="glassfish" default="true">

                 <configuration>

                     <property name="sunResourcesXml">src/main/setup/glassfish-resources.xml</property>       

                 </configuration>

             </container>

             <engine>

                          <property name="deploymentExportPath">target</property>

                </engine>

      </arquillian>

      {code}

       

       

      persistence.xml

       

       

      {code: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="betbot_ejb_pu" transaction-type="JTA">

          <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

          <jta-data-source>java:app/jdbc/betbot</jta-data-source>

          <exclude-unlisted-classes>false</exclude-unlisted-classes>

          <properties>

            <property name="eclipselink.ddl-generation" value="create-tables"/>

          </properties>

        </persistence-unit>

      </persistence>

      {code}

       

      glassfish-resources.xml

       

       

      {code:xml}<?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">

      <resources>

          <jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.postgresql.ds.PGSimpleDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="post-gre-sql_betbot_betfairPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">

              <property name="serverName" value="127.0.0.1"/>

              <property name="portNumber" value="5432"/>

              <property name="databaseName" value="betbot"/>

              <property name="User" value="xxx"/>

              <property name="Password" value="xxx"/>

              <property name="URL" value="jdbc:postgresql://127.0.0.1:5432/betbot"/>

              <property name="driverClass" value="org.postgresql.Driver"/>

          </jdbc-connection-pool>

          <jdbc-resource enabled="true" jndi-name="jdbc/betbot" object-type="user" pool-name="post-gre-sql_betbot_betfairPool"/>

      </resources>

      {code}

       

      Deployment method from test case

       

       

      {code}

      @Deployment

         public static JavaArchive createTestArchive() {

            return ShrinkWrap.create(JavaArchive.class, "test.jar")

               .addClasses(PublisherPersistenceService.class)

               .addAsManifestResource(

                  "META-INF/test-persistence.xml",

                  ArchivePaths.create("persistence.xml"))

               .addAsManifestResource(

                  EmptyAsset.INSTANCE,

                  ArchivePaths.create("beans.xml"));

         }

      {code}

       

        • 1. Re: Resource not found using Embedded Glassfish 3.1
          aslak

          Which Arquillian v ?

          • 2. Re: Resource not found using Embedded Glassfish 3.1
            mcgin

            Oops forgot to include that, its 1.0.0Alpha5

            • 3. Re: Resource not found using Embedded Glassfish 3.1
              aslak

              Alpha5 missed the support for sunResourceXML for GF 3.1

               

              Try Arquillian Core 1.0.0.CR1 and Arquillian GlassFish 1.0.0.CR1-SNAPSHOT

              • 4. Re: Resource not found using Embedded Glassfish 3.1
                mcgin

                Thanks Aslak, that did it.  However, now I've run into an unknown entity type error which has me stumped.  Nothing to do with Arquillian so going to have to dig into my JPA config

                 

                 

                Caused by: java.lang.IllegalArgumentException: Object: com.gamblerstools.betbot.model.Publisher[ id=null, name=Betfair, url=http://www.betfair.com ] is not a known entity type.

                 

                 

                {code}

                package com.gamblerstools.betbot.model;

                 

                 

                import java.io.Serializable;

                import javax.persistence.Entity;

                import javax.persistence.GeneratedValue;

                import javax.persistence.GenerationType;

                import javax.persistence.Id;

                 

                 

                /**

                *

                * @author Laptop

                */

                @Entity

                public class Publisher implements Serializable {

                    private static final long serialVersionUID = 1L;

                    @Id

                    @GeneratedValue(strategy = GenerationType.AUTO)

                    private Long id;

                 

                 

                   

                    private String url;

                    private String name;

                   

                    public String getName() {

                        return name;

                    }

                 

                 

                    public void setName(String name) {

                        this.name = name;

                    }

                 

                 

                    public String getUrl() {

                        return url;

                    }

                 

                 

                    public void setUrl(String url) {

                        this.url = url;

                    }

                   

                    public Long getId() {

                        return id;

                    }

                 

                 

                    public void setId(Long id) {

                        this.id = id;

                    }

                 

                 

                    @Override

                    public int hashCode() {

                        int hash = 0;

                        hash += (id != null ? id.hashCode() : 0);

                        return hash;

                    }

                 

                 

                    @Override

                    public boolean equals(Object object) {

                        // TODO: Warning - this method won't work in the case the id fields are not set

                        if (!(object instanceof Publisher)) {

                            return false;

                        }

                        Publisher other = (Publisher) object;

                        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {

                            return false;

                        }

                        return true;

                    }

                 

                 

                    @Override

                    public String toString() {

                        return "com.gamblerstools.betbot.model.Publisher[ id=" + id

                                + ", name="+name+", url="+url+" ]";

                    }

                   

                }{code}

                 

                • 5. Re: Resource not found using Embedded Glassfish 3.1
                  mcgin

                  Explicitly adding the class to the persistence.xml solved the problem.  Seems like the autodiscovery doesn't work too well....

                   

                   

                  {code: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="betbot_ejb_pu" transaction-type="JTA">

                      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

                      <jta-data-source>jdbc/betbot</jta-data-source>

                      <class>com.gamblerstools.betbot.model.Publisher</class>

                      <exclude-unlisted-classes>true</exclude-unlisted-classes>

                      <properties>

                        <property name="eclipselink.ddl-generation" value="create-tables"/>

                      </properties>

                    </persistence-unit>

                  </persistence>

                  {code}

                   

                  1 of 1 people found this helpful