2 Replies Latest reply on Oct 23, 2006 8:04 AM by Mohammad Norouzi

    How to configure an embedded Ejb to connect to MySql?

    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.
      every document I see has an example with Hsqldb.

      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>
      


      and 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>
      
      


      and this is exception message I receive:
      
      (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.Def
       aultInterc
       eptorMarker to com.seam.web.action.RegisterAction org.jboss.annotation.internal.DefaultInterceptorMa
       rkerImpl@5
       f0e7d
       (ejb3.Ejb3Deployment 467 ) EJB3 deployment time took: 1656
       (ejb3.MCKernelAbstraction 84 ) installing bean: persistence.units:jar=registration-web.j
       ar,unitNam
       e=testDatabase with dependencies:
       (ejb3.MCKernelAbstraction 87 ) AbstractDependencyMetaData@9719f4{dependency=testDat
       asource}
       (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.conn
       ection.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.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)
       at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnecti
       on(LocalMa
       nagedConnectionFactory.java:177)
       at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventL
       istener(In
       ternalManagedConnectionPool.java:579)
       at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(Internal
       ManagedCon
       nectionPool.java:247)
       at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JB
       ossManaged
       ConnectionPool.java:540)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConn
       ectionMana
       ger2.java:339)
       at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectio
       nManager.j
       ava:301)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnec
       tionManage
       r2.java:392)
       at org.jboss.resource.adapter.jdbc.local.LocalTxDataSource$ConnectionManagerDelegate.allocat
       eConnectio
       n(LocalTxDataSource.java:78)
       at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88
       )
       at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionP
       rovider.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(HibernatePersi
       stence.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(ReflectMethodInfoImp
       l.java:107
       )
       at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextActions.dispatchJoinPoint(Kern
       elControll
       erContextActions.java:100)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextActions$LifecycleAction.instal
       lAction(Ke
       rnelControllerContextActions.java:582)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextActions$KernelControllerContex
       tAction.in
       stall(KernelControllerContextActions.java:175)
       at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerC
       ontextActi
       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:34
       6)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:4
       38)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:3
       79)
       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(AbstractKernelContro
       ller.java:
       79)
       at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelContro
       ller.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 UR
       L: 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(LocalManage
       dConnectio
       nFactory.java:288)
       at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnecti
       on(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.resou
       rce.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 conn
       ection; -
       nested throwable: (org.jboss.resource.JBossResourceException: Apparently wrong driver class specifie
       d 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(DatasourceConnectionP
       rovider.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(HibernatePersi
       stence.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(ReflectMethodInfoImp
       l.java:107
       )
       at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextActions.dispatchJoinPoint(Kern
       elControll
       erContextActions.java:100)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextActions$LifecycleAction.instal
       lAction(Ke
       rnelControllerContextActions.java:582)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextActions$KernelControllerContex
       tAction.in
       stall(KernelControllerContextActions.java:175)
       at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerC
       ontextActi
       ons.java:51)