7 Replies Latest reply on Oct 28, 2006 5:54 AM by Mohammad Norouzi

    How to configure an embedded Ejb to connect to MySql not Hsq

    Mohammad Norouzi Novice

      Hi all
      I have a problem connection the embedded Ejb to a database other than Hsqldb that currently used in all Seam examples.
      I am using registration example and change its config files to connect to MySql but it doesnt work. I want to use Ejb persistence.

      any help greatly appreciated.

      here is my config files:

      persistence.xml

      
      <persistence>
       <persistence-unit name="testDatabase">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <!-- -->
      
       <jta-data-source>testDatasource</jta-data-source>
       <properties>
       <property name="hibernate.hbm2ddl.auto" value="update" />
       <property name="hibernate.show_sql" value="true" />
       <!-- These are the default for JBoss EJB3, but not for HEM: -->
       <property name="hibernate.cache.provider_class"
       value="org.hibernate.cache.HashtableCacheProvider" />
       <property name="hibernate.transaction.manager_lookup_class"
       value="org.hibernate.transaction.JBossTransactionManagerLookup" />
       <property name="hibernate.dialect"
       value="org.hibernate.dialect.MySQLDialect" />
       </properties>
       </persistence-unit>
       </persistence>
      


      jboss-beans.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
       xmlns="urn:jboss:bean-deployer:2.0">
      
       <bean name="testDatasourceBootstrap"
       class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
      
       <property name="driverClass">com.mysql.jdbc.Driver</property>
       <property name="connectionURL">
       jdbc:mysql://192.168.0.157:3306/seamtest?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF8
       </property>
       <property name="userName">root</property>
       <property name="password">root</property>
       <property name="jndiName">testDatasource</property>
       <property name="minSize">0</property>
       <property name="maxSize">10</property>
       <property name="blockingTimeout">1000</property>
       <property name="idleTimeout">100000</property>
       <property name="transactionManager">
       <inject bean="TransactionManager" />
       </property>
       <property name="cachedConnectionManager">
       <inject bean="CachedConnectionManager" />
       </property>
       <property name="initialContextProperties">
       <inject bean="InitialContextProperties" />
       </property>
       </bean>
      
       <bean name="testDatasource" class="java.lang.Object">
       <constructor factoryMethod="getDatasource">
       <factory bean="testDatasourceBootstrap" />
       </constructor>
       </bean>
      
      </deployment>
      




      I get following exception:
      (core.Ejb 94 ) starting the embedded EJB container
      (xml.BeanSchemaBinding 227 ) You should use the 2.0 version of the Microcontainer xml. xmlns='ur
      n:jboss:bean-deployer:2.0'
      (local.LocalTxDataSource 117 ) Bound datasource to JNDI name 'java:/DefaultDS'
      (local.LocalTxDataSource 117 ) Bound datasource to JNDI name 'testDatasource'
      (ejb3.Ejb3DescriptorHandler 1699) adding class annotation org.jboss.annotation.internal.DefaultInterc
      eptorMarker to com.seam.web.action.RegisterAction org.jboss.annotation.internal.DefaultInterceptorMarkerImpl@5
      f0e7d
      (ejb3.Ejb3Deployment 467 ) EJB3 deployment time took: 1656
      (ejb3.MCKernelAbstraction 84 ) installing bean: persistence.units:jar=registration-web.jar,unitNam
      e=testDatabase with dependencies:
      (ejb3.MCKernelAbstraction 87 ) AbstractDependencyMetaData@9719f4{dependency=testDatasource}
      (ejb.Version 94 ) Hibernate EntityManager 3.2.0.CR1
      (annotations.Version 94 ) Hibernate Annotations 3.2.0.CR1
      (cfg.Environment 94 ) Hibernate 3.2 cr2
      (cfg.Environment 94 ) hibernate.properties not found
      (cfg.Environment 94 ) Bytecode provider name : cglib
      (cfg.Environment 94 ) using JDK 1.4 java.sql.Timestamp handling
      (ejb.Ejb3Configuration 94 ) Processing PersistenceUnitInfo [
       name: testDatabase
       ...]
      (ejb.Ejb3Configuration 94 ) found EJB3 Entity bean: com.seam.dto.User
      (ejb.Ejb3Configuration 104 ) Persistence provider caller does not implements the EJB3 spec corre
      ctly. PersistenceUnitInfo.getNewTempClassLoader() is null.
      (cfg.Configuration 94 ) Reading mappings from resource: META-INF/orm.xml
      (ejb.Ejb3Configuration 94 ) [PersistenceUnit: testDatabase] no META-INF/orm.xml found
      (cfg.AnnotationBinder 94 ) Binding entity from annotated class: com.seam.dto.User
      (annotations.EntityBinder 94 ) Bind entity com.seam.dto.User on table user
      (connection.ConnectionProviderFactory 94 ) Initializing connection provider: org.hibernate.ejb.connection.Inj
      ectedDataSourceConnectionProvider
      (connection.InjectedDataSourceConnectionProvider 94 ) Using provided datasource
      (local.LocalTxDataSource 271 ) Throwable while attempting to get a new connection: null
      org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resourc
      e.JBossResourceException: Apparently wrong driver class specified for URL: class: com.mysql.jdbc.Driver, url:
      
       jdbc:mysql://192.168.0.157:3306/seamtest?autoReconnect=true&useUnicode=true&characterE
      ncoding=UTF8)
       at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalMa
      nagedConnectionFactory.java:177)
       at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(In
      ternalManagedConnectionPool.java:579)
       at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedCon
      nectionPool.java:247)
       at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManaged
      ConnectionPool.java:540)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionMana
      ger2.java:339)
       at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.j
      ava:301)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManage
      r2.java:392)
       at org.jboss.resource.adapter.jdbc.local.LocalTxDataSource$ConnectionManagerDelegate.allocateConnectio
      n(LocalTxDataSource.java:78)
       at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
       at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.ja
      va:69)
       at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:73)
       at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1928)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:631)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:760)
       at org.hibernate.ejb.Ejb3Configuration.createContainerEntityManagerFactory(Ejb3Configuration.java:350)
      
       at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.jav
      a:119)
       at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
       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.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:55)
       at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:107
      )
       at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextActions.dispatchJoinPoint(KernelControll
      erContextActions.java:100)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextActions$LifecycleAction.installAction(Ke
      rnelControllerContextActions.java:582)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextActions$KernelControllerContextAction.in
      stall(KernelControllerContextActions.java:175)
       at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActi
      ons.java:51)
       at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:226)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:593)
       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:346)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:438)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:379)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:225)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:151)
       at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:
      79)
       at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:
      73)
       at org.jboss.ejb3.MCKernelAbstraction.install(MCKernelAbstraction.java:91)
       at org.jboss.ejb3.Ejb3Deployment.startPersistenceUnits(Ejb3Deployment.java:626)
       at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:475)
       at org.jboss.ejb3.embedded.EJB3StandaloneDeployer.start(EJB3StandaloneDeployer.java:460)
       at org.jboss.seam.core.Ejb.startup(Ejb.java:50)
       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.seam.util.Reflections.invoke(Reflections.java:13)
       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:32)
       at org.jboss.seam.Component.callComponentMethod(Component.java:1334)
       at org.jboss.seam.Component.callCreateMethod(Component.java:1322)
       at org.jboss.seam.Component.newInstance(Component.java:1312)
       at org.jboss.seam.Component.getInstance(Component.java:1263)
       at org.jboss.seam.Component.getInstance(Component.java:1253)
       at org.jboss.seam.contexts.Lifecycle.startup(Lifecycle.java:125)
       at org.jboss.seam.contexts.Lifecycle.endInitialization(Lifecycle.java:104)
       at org.jboss.seam.init.Initialization.init(Initialization.java:196)
       at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:32)
       at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3669)
       at org.apache.catalina.core.StandardContext.start(StandardContext.java:4104)
       at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
       at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
       at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
       at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:788)
       at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:677)
       at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:473)
       at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1102)
       at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
       at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
       at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020)
       at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
       at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
       at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
       at org.apache.catalina.core.StandardService.start(StandardService.java:450)
       at org.apache.catalina.core.StandardServer.start(StandardServer.java:683)
       at org.apache.catalina.startup.Catalina.start(Catalina.java:537)
       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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)
       at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)
      Caused by: org.jboss.resource.JBossResourceException: Apparently wrong driver class specified for URL: class:
      com.mysql.jdbc.Driver, url:
       jdbc:mysql://192.168.0.157:3306/seamtest?autoReconnect=true&useUnicode=true&characterE
      ncoding=UTF8
       at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getDriver(LocalManagedConnectio
      nFactory.java:288)
       at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalMa
      nagedConnectionFactory.java:168)
       ... 81 more
      (cfg.SettingsFactory 109 ) Could not obtain connection metadata
      org.jboss.util.NestedSQLException: Could not create connection; - nested throwable: (org.jboss.resource.JBossR
      esourceException: Apparently wrong driver class specified for URL: class: com.mysql.jdbc.Driver, url:
       jdbc:mysql://192.168.0.157:3306/seamtest?autoReconnect=true&useUnicode=true&characterE
      ncoding=UTF8); - nested throwable: (org.jboss.resource.JBossResourceException: Could not create connection; -
      nested throwable: (org.jboss.resource.JBossResourceException: Apparently wrong driver class specified for URL:
       class: com.mysql.jdbc.Driver, url:
       jdbc:mysql://192.168.0.157:3306/seamtest?autoReconnect=true&useUnicode=true&characterE
      ncoding=UTF8))
       at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:94)
       at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.ja
      va:69)
       at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:73)
       at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1928)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:631)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:760)
       at org.hibernate.ejb.Ejb3Configuration.createContainerEntityManagerFactory(Ejb3Configuration.java:350)
      
       at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.jav
      a:119)
       at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
       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.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:55)
       at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:107
      )
       at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextActions.dispatchJoinPoint(KernelControll
      erContextActions.java:100)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextActions$LifecycleAction.installAction(Ke
      rnelControllerContextActions.java:582)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextActions$KernelControllerContextAction.in
      stall(KernelControllerContextActions.java:175)
       at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActi
      ons.java:51)
      [color]
      


        • 1. Re: How to configure an embedded Ejb to connect to MySql not
          Mohammad Norouzi Novice

          RESOLVED

          after many toiling I could resolve the problem. it is something bizarre!!!

          in the persistence.xml I put following property because I am using MySql:

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


          but after googling and surfing many pages (maybe all the web ;) ) I found a document in german language and I could understands only its codes and I see they used following property with MySql Database connection:

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


          and now it is working, I dont understand why we should use HSQLDialect rather than MySQLDialect whereas we are going to connect to mysql ???
          if anyone knows I am looking forward to know as well.


          I reply this to help the others that have or will have my problem.

          • 2. Re: How to configure an embedded Ejb to connect to MySql not
            Carsten Hoehne Master

            Hello,
            First, try to not use autoReconnect

            <property name="connectionURL">
             jdbc:mysql://192.168.0.157:3306/seamtest?autoReconnect=true&useUnicode=true&characterEncoding=UTF8
            

            From the MySQL Connector/J documentation about autoReconnect:
            The use of this feature is
            not recommended, because it has side effects
            related to session state and data consistency
            when applications don'thandle SQLExceptions
            properly, and is only designed to be used
            when you are unable to configure your application
            to handle SQLExceptions resulting from
            dead andstale connections properly.

            Second:
            org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jbo
            ss.resourc
            e.JBossResourceException: Apparently wrong driver class specified for URL: class: com.mysql.jdbc.Dri
            ver, url:
            
             jdbc:mysql://192.168.0.157:3306/seamtest?autoReconnect=true&useUnicode=true&characterE
            ncoding=UTF8)
            

            When yozu have to specify HSQLDialect then there is something wrong with your configuration. Sorry i am not able to figure it out.
            MySQL is running fine in my apps with dialect set to org.hibernate.dialect.MySQLInnoDBDialect.
            Some suggestions:


            * doublecheck that the mysql connection library is found
            * omit parameters from mysql connection string
            * grep for 'hsql' in your complete project


            Hope that helps.
            Ciao,
            Carsten

            • 3. Re: How to configure an embedded Ejb to connect to MySql not
              Mohammad Norouzi Novice

              Hi baz,

              I checked mySql driver connector and it works in a non-Ejb project.

              and also I remove additional parameters from connectionstring but nothing has changed.

              about your third solution, would you please explain more?

              thanks

              • 4. Re: How to configure an embedded Ejb to connect to MySql not
                Gavin King Master

                 

                I reply this to help the others that have or will have my problem.


                If other people have the same problem as you, they should most certainly not try to fix it by using the wrong Hibernate dialect. Sheesh!

                • 5. Re: How to configure an embedded Ejb to connect to MySql not
                  Mohammad Norouzi Novice

                  Hi Gavin

                  first, as I said before, I learn this from a ducument about Ejb and Jsf in german language and they connected to MySql with Hsqldb dialect, and I said it is strange but only after that it worked. However, my configuration is exactly correct but it doesnt work with MySql dialect so maybe it is a bug in the Seam. now I am at home and can not show you the link that refers to that document.

                  second, I didnt say that all people go and change their dialect as I change it, I just wanted they know I passed these works to resolve my problem, maybe some one who know more, could find the exact reason of this weird problem and reply to this thread.

                  if only, you had said your idea about this and had said why this happen.

                  • 6. Re: How to configure an embedded Ejb to connect to MySql not
                    Carsten Hoehne Master

                    Hello,

                    about your third solution, would you please explain more?

                    Sure.
                    try to search your complete project for the string hsql.
                    Not only the source code, check the generated artifacts also.
                    Even check the deployed project.
                    There must be an erroneus configuration. And this need to be found.

                    If nothing helps, begin from scratch.
                    Ciao,
                    Carsten

                    • 7. Re: How to configure an embedded Ejb to connect to MySql not
                      Mohammad Norouzi Novice

                      Hi baz,

                      I search all the project even inside the jar files but there is no "hsql" string except the one I put as HSQLDialect and two others that placed in mc-conf.jar file and I dont think mc-conf.jar has something to do with this problem.

                      any way, thank you so much, if any more suggestion please send to this thread.