Thursday, April 28, 2011

Migrate JBoss db from Hypersonic to MySql

Quick steps to do this migration:

Versions: JBoss 4.2.2, MySql 5.0.77

1. Copy MySql drive jar to to <JBOSS_HOME>/server/default/lib directory. (For example, mysql-connector-java-5.0.5-bin.jar)

2. Remove <JBOSS_HOME>/server/default/deploy/hsqldb-ds.xml

3. Copy <JBOSS_HOME>/docs/examples/jca/mysql-ds.xml to <JBOSS_HOME>/server/default/deploy. Update JNDI-Name, Connection-URL, User-Name and Password tags in this file to your application specific values.
For example, In my case, the values were -
<jndi-name>DefaultDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/jbossdb?createDatabaseIfNotExist=true</connection-url>
('createDatabaseIfNotExist' flag will create 'jbossdb' automatically if it doesn't exist)
<user-name>your_user</user-name>
<password>your_password</password>

4. Update tags 'datasource-mapping' and 'fk-constraint' in <JBOSS_HOME>/server/default/conf/standardjbosscmp-jdbc.xml to following values:
<datasource-mapping>mySQL</datasource-mapping>
<fk-constraint>true</fk-constraint>

5. Add following 'application-policy' in <JBOSS_HOME>/server/default/conf/login-config.xml
<application-policy name = "MySqlDbRealm">
<authentication>
<login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
<module-option name = "principal">your_user</module-option>
<module-option name = "userName">your_user</module-option>
<module-option name ="password">your_pass</module-option>
<module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=DefaultDS</module-option>
</login-module>
</authentication>
</application-policy>

6. In <JBOSS_HOME>/server/default/deploy/jms directory, replace file hsql-jdbc2-service.xml by file <JBOSS_HOME>/docs/examples/jms/mysql-jdbc2-service.xml and change the one mention of MySqlDS to DefaultDS.

7. Rename hsqldb-jdbc-state-service.xml to mysql-jdbc-state-service.xml. (No changes)


This post should help for given versions of the software for sure.

1 comment: