3 Replies Latest reply on Sep 1, 2010 11:06 AM by franck lepretre

    EJB3 and persistence in JBOSS 6.0.0

    franck lepretre Newbie

      Hi,

       

      will I was testing Jboss 6, I found out that a Session Bean I created cannot be accessed anymore when I add the persistentContext attribute in the code:

       

      @PersistenceContext(unitName = "bookshopUnit")
      protected EntityManager em;

       

      When I add this, the bean is not referenced in JNDI, and cannot be accessed.

       

      In the log I can see

      14:30:22,062 INFO  [org.jboss.ejb3.deployers.JBossASKernel] Created KernelDeployment for: bookshopEjb.jar
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel] installing bean: jboss.j2ee:ear=testEAR.ear,jar=bookshopEjb.jar,name=BookShop,service=EJB3
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   with dependencies:
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and demands:
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jboss.ejb:service=EJBTimerService; Required: Described
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and supplies:
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jndi:testEAR/BookShop/remote
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jndi:testEAR/BookShop/local
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jndi:BookShop
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jndi:testEAR/BookShop/remote-com.sqli.bookshop.facade.BookShopFacadeRemote
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     Class:com.bookshop.facade.BookShopFacadeRemote
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jndi:testEAR/BookShop/local-com.bookshop.facade.BookShopFacadeLocal
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     Class:com.bookshop.facade.BookShopFacadeLocal
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel] Added bean(jboss.j2ee:ear=testEAR.ear,jar=bookshopEjb.jar,name=BookShop,service=EJB3) to KernelDeployment of: bookshopEjb.jar
      14:30:22,078 INFO  [org.jboss.ejb3.deployers.JBossASKernel] installing bean: jboss.j2ee:ear=testEAR.ear,jar=bookshopEjb.jar,name=ShoppingCart,service=EJB3

      ---> Bean cannot be accessed with JNDI anymore

       

      When I try to access this bean through JNDI, I get BookShop not bound.

      When I remove the persistentContext from the code, my Java client can access the bean with JNDI.

       

      Do I miss something ?

       

      Thanks

      Franck

        • 1. Re: EJB3 and persistence in JBOSS 6.0.0
          jaikiran pai Master

          Please post the entire exception stacktrace, the exact version of JBoss AS 6.0 and also the persistence.xml file. Additionally please also post the JNDI tree output which can be viewed as explained here http://community.jboss.org/wiki/DisplayTheJDNITreeWithTheJMXConsole

          • 2. Re: EJB3 and persistence in JBOSS 6.0.0
            franck lepretre Newbie

            There is no stack Trace.

            Jboss log does not show that the JNDI name of the bean is registered.

             

            When the persistenceContext is commented out, I get the JNDI information in the log

             

            15:20:36,328 INFO  [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

             

                BookShopFacade/remote - EJB3.x Default Remote Business Interface
                testEAR/BookShop/remote-com.sqli.bookshop.facade.BookShopFacadeRemote - EJB3.x Remote Business Interface
                BookShopFacade/local - EJB3.x Default Local Business Interface
                testEAR/BookShop/local-com.sqli.bookshop.facade.BookShopFacadeLocal - EJB3.x Local Business Interface

             

             

            The persistence.xml is:

            <?xml version="1.0" encoding="UTF-8"?>
            <persistence 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_1_0.xsd
                          version="1.0">
            <persistence-unit name="bookShopUnit" transaction-type="JTA">
              <jta-data-source>java:/bookShopDS</jta-data-source>
            <properties>
              <property name="hibernate.hbm2ddl.auto" value="update" />
              <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
              </properties>
              </persistence-unit>
              </persistence>

             

             

            The JNDI from the console is:



            java:

            securityManagement
            org.jboss.security.integration.JNDIBasedSecurityManagement


            comp
            javax.naming.Context


            XAConnectionFactory
            org.hornetq.jms.client.HornetQConnectionFactory


            JmsXA
            org.hornetq.ra.HornetQRAConnectionFactoryImpl


            policyRegistration
            org.jboss.security.plugins.JBossPolicyRegistration


            TransactionPropagationContextImporter
            com.arjuna.ats.internal.jbossatx.jta.PropagationContextManager


            Failed to lookup: app, errmsg=java:app not supported by legacy component null


            app
            javax.naming.Context


            Mail
            javax.mail.Session


            TransactionPropagationContextExporter
            com.arjuna.ats.internal.jbossatx.jta.PropagationContextManager


            ProfileService
            org.jboss.profileservice.AbstractProfileService


            DefaultDS
            org.jboss.resource.adapter.jdbc.WrapperDataSource


            jaas
            javax.naming.Context

            HsqlDbRealm
            org.jboss.security.plugins.SecurityDomainContext


            hornetq
            org.jboss.security.plugins.SecurityDomainContext


            jboss-web-policy
            org.jboss.security.plugins.SecurityDomainContext



            TransactionSynchronizationRegistry
            com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple


            SecurityProxyFactory
            org.jboss.security.SubjectSecurityProxyFactory


            ConnectionFactory
            org.hornetq.jms.client.HornetQConnectionFactory


            DefaultJMSProvider
            org.jboss.jms.jndi.JNDIProviderAdapter


            TransactionManager
            com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate


            timedCacheFactory
            javax.naming.Context

            Failed to list contents of: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy cannot be cast to javax.naming.NamingEnumeration



            Failed to lookup: module, errmsg=java:module not supported by legacy component null


            module
            javax.naming.Context


            internal
            org.jnp.interfaces.NamingContext

            EJBContext
            javax.ejb.EJBContext


            TimerService
            javax.ejb.TimerService



            global
            org.jnp.interfaces.NamingContext

            jmx-console
            org.jnp.interfaces.NamingContext

            ModuleName
            java.lang.String



            scheduler-service
            org.jnp.interfaces.NamingContext

            AppName
            java.lang.String



            testEJB
            org.jnp.interfaces.NamingContext

            ModuleName
            java.lang.String



            ROOT
            org.jnp.interfaces.NamingContext

            ModuleName
            java.lang.String



            schedule-manager-service
            org.jnp.interfaces.NamingContext

            AppName
            java.lang.String



            mail-service
            org.jnp.interfaces.NamingContext

            AppName
            java.lang.String



            testEAR
            org.jnp.interfaces.NamingContext

            bookShopWeb
            org.jnp.interfaces.NamingContext

            ModuleName
            java.lang.String



            bookshopEjb
            org.jnp.interfaces.NamingContext

            ModuleName
            java.lang.String



            AppName
            java.lang.String



            monitoring-service
            org.jnp.interfaces.NamingContext

            AppName
            java.lang.String



            cache-invalidation-service
            org.jnp.interfaces.NamingContext

            AppName
            java.lang.String



            properties-service
            org.jnp.interfaces.NamingContext

            AppName
            java.lang.String



            uuid-key-generator
            org.jnp.interfaces.NamingContext

            AppName
            java.lang.String



            transaction-service
            org.jnp.interfaces.NamingContext

            AppName
            java.lang.String



            ejb2-timer-service
            org.jnp.interfaces.NamingContext

            AppName
            java.lang.String



            legacy-conf-service
            org.jnp.interfaces.NamingContext

            AppName
            java.lang.String



            http-invoker
            org.jnp.interfaces.NamingContext

            invoker
            org.jnp.interfaces.NamingContext

            ModuleName
            java.lang.String



            AppName
            java.lang.String



            sqlexception-service
            org.jnp.interfaces.NamingContext

            AppName
            java.lang.String



            legacy-invokers-service
            org.jnp.interfaces.NamingContext

            AppName
            java.lang.String



            jsr88-service
            org.jnp.interfaces.NamingContext

            AppName
            java.lang.String





            Global

            UserTransactionSessionFactory
            $Proxy112


            UUIDKeyGeneratorFactory
            org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory


            HiLoKeyGeneratorFactory
            org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory


            SecureDeploymentManager
            org.jnp.interfaces.NamingContext

            remote
            DeploymentManager
            javax.naming.LinkRef



            SecureManagementView
            org.jnp.interfaces.NamingContext

            remote
            ManagementView
            javax.naming.LinkRef



            DeploymentManager
            org.jboss.aop.generatedproxies.AOPProxy$4


            XAConnectionFactory
            org.hornetq.jms.client.HornetQConnectionFactory


            ProfileService
            org.jboss.aop.generatedproxies.AOPProxy$2


            SecureProfileService
            org.jnp.interfaces.NamingContext

            remote
            ProfileService
            javax.naming.LinkRef



            queue
            org.jnp.interfaces.NamingContext

            DLQ
            org.hornetq.jms.client.HornetQQueue


            ExpiryQueue
            org.hornetq.jms.client.HornetQQueue



            UserTransaction
            org.jboss.tm.usertx.client.ClientUserTransaction


            ConnectionFactory
            org.hornetq.jms.client.HornetQConnectionFactory


            jmx
            org.jnp.interfaces.NamingContext

            invoker
            org.jnp.interfaces.NamingContext

            RMIAdaptor
            javax.management.MBeanServerConnection



            rmi
            org.jnp.interfaces.NamingContext

            RMIAdaptor
            javax.management.MBeanServerConnection




            BeanValidatorFactories
            org.jnp.interfaces.NamingContext


            persistence.unit:unitName=#timerdb
            org.hibernate.impl.SessionFactoryImpl


            TomcatAuthenticators
            java.util.Properties


            XAThroughputConnectionFactory
            org.hornetq.jms.client.HornetQConnectionFactory


            ManagementView
            org.jboss.aop.generatedproxies.AOPProxy$3


            ThroughputConnectionFactory
            org.hornetq.jms.client.HornetQConnectionFactory

            Thanks Franck

            • 3. Re: EJB3 and persistence in JBOSS 6.0.0
              franck lepretre Newbie

              the problem was in the datasource.

              For this version it is necessary to have a datasource like this:

              <datasources>
                <local-tx-datasource>
                    <jndi-name>bookShopDS</jndi-name>
                  <connection-url>jdbc:mysql://localhost:3306/bookshop</connection-url>
                  <driver-class>com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource</driver-class>
                  <user-name>sqli</user-name>
                  <password>sqli</password>
                  <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
                  <metadata>
                      <type-mapping>mySQL</type-mapping>

               

                  </metadata>
                </local-tx-datasource>
              </datasources>

               

              I did not have </local-tx-datasource> and it created this weird situation.

               

              Franck