3 Replies Latest reply on Oct 6, 2005 12:31 AM by nalla adi

    how to write persistence.xml to use mysql in ejb3

    nalla adi Newbie

      I am trying to write the persistence.xml to use mysql. Basically i have plain pojo program which uses the @Resource in stateless bean.
      Something like this:
      @Resource (name="dbro")
      protected DataSource dbro;

      Now in respective .ejb3 file, i need to put the persistence.xml. How to write the user/pwd/driver/no. of connections in pool etc., . All examples are hibernate specific.

      Thanks,
      Bhaskar

        • 1. Re: how to write persistence.xml to use mysql in ejb3
          nalla adi Newbie

          I have a simple EJB to connect to mysql. I don't know how to specify the mysql connection details. can someone help me please.

          My test ejb has following files:
          META-INF/MANIFEST.MF
          dd/persistence/persistence.xml
          jndi.properties
          src/Test.class
          src/TestBean.class
          src/web/TestServlet.class
          web.xml

          Here is how i put the content in persistence.xml:

          <entity-manager>

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


          driverClassName
          com.mysql.jdbc.Driver



          url
          jdbc:mysql://66.228.161.34/games



          username
          ygames



          password
          <![CDATA[8gm7<WEtc]]>




          </entity-manager>

          Here is how i inject the datasource inside my stateless TestBean:

          @Resource (name="GamesDB")
          DataSource myDb;


          then myDb.getConnection();

          While deploying itself, jboss fails with following exception:
          12:47:23,593 WARN [ServiceController] Problem starting service jboss.j2ee:service=EJB3,name=src.TestBean
          javax.naming.NameNotFoundException: GamesDB not bound
          at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
          at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
          at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
          at org.jnp.server.NamingServer.lookup(NamingServer.java:278)
          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
          at javax.naming.InitialContext.lookup(InitialContext.java:351)
          at org.jboss.ejb3.injection.ResourceHandler.loadFieldInjectors(ResourceHandler.java:174)
          at org.jboss.ejb3.injection.ResourceHandler.loadInjectors(ResourceHandler.java:122)
          at org.jboss.ejb3.EJBContainer.resolveInjectors(EJBContainer.java:297)
          at org.jboss.ejb3.EJBContainer.initializePool(EJBContainer.java:238)
          at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:208)
          at org.jboss.ejb3.SessionContainer.start(SessionContainer.java:43)
          at org.jboss.ejb3.stateless.StatelessContainer.start(StatelessContainer.java:64)
          at org.jboss.ejb3.stateless.StatelessManager.startService(StatelessManager.java:88)
          at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:287)
          at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:236)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:585)
          at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
          at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
          at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
          at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
          at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
          at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:974)
          at $Proxy0.start(Unknown Source)
          at org.jboss.system.ServiceController.start(ServiceController.java:453)
          at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:585)
          at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
          at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
          at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
          at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
          at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
          at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
          at $Proxy83.start(Unknown Source)
          at org.jboss.ejb3.Ejb3JmxDeployment.start(Ejb3JmxDeployment.java:175)
          at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:39)
          at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:287)
          at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:236)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:585)
          at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
          at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
          at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
          at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
          at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
          at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:974)
          at $Proxy0.start(Unknown Source)
          at org.jboss.system.ServiceController.start(ServiceController.java:453)
          at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:585)
          at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
          at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
          at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
          at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
          at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
          at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
          at $Proxy10.start(Unknown Source)
          at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:198)
          at org.jboss.deployment.MainDeployer.start(MainDeployer.java:973)
          at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:774)
          at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:737)
          at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:585)
          at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
          at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
          at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:118)
          at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
          at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127)
          at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
          at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
          at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
          at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
          at $Proxy6.deploy(Unknown Source)
          at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:319)
          at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:489)
          at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:192)
          at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:203)
          at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:182)
          12:47:23,625 INFO [EJB3Deployer] Deployed: file:/C:/jboss-4.0.3RC2/server/default/deploy/test-beans.ejb3
          12:47:23,656 ERROR [URLDeploymentScanner] Incomplete Deployment listing:


          This means, i am not specifying the connection details in proper place.

          Can someone guide me how to specify the database connection details for mysql.

          • 2. Re: how to write persistence.xml to use mysql in ejb3
            Guilherme Melo e Maranhão Newbie

            You don't want to use Hibernate, do you?
            I am using Hibernate and got this exception. To solve it I change the jta-data-source, to java:/DefaultDS, which is the default jta-data-source of Hibernate.
            It solves the problem of "not bound it", but now I got this error:
            javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not instantiate dialect class.
            And I am using MySql too.
            Did you have any idea? Did you solve your problem?

            Thanks, Guilherme

            • 3. Re: how to write persistence.xml to use mysql in ejb3
              nalla adi Newbie

              I don't want to use hibernate.
              I want to write a simple stateless session bean. I want to make a connection from this bean to mysql db.
              I want to define the connection parameters and pooling parameters.
              How to do ? where to do?

              I searched in all the corners of jboss documentation. Probably I am missing something else so, I really appreciate if someone point me to the right documentation.

              Thanks a million in advance,
              Bhaskar