The default data source in WildFly 8.1 is configured with the H2 database engine. There are several options available for a database. The top four most commonly used relational databases are Oracle database, MySQL database, SQL Server, and PostgreSQL Server. Oracle database and SQL Server are designed for enterprise level applications and are not open source. Oracle database offers more features to facilitate system and data maintenance. It also offers features to prevent system and data failure as compared to SQL Server. MySQL and PostgreSQL are open source databases with comparable features and designed primarily for small scale applications. We will use MySQL database. Some of the reasons to choose MySQL are discussed at http://www.mysql.com/why-mysql/topreasons.html.
We will configure a datasource with the MySQL database for use in the EJB 3.x application for object/relational mapping. Use the following steps to configure a datasource:
%JBOSS_HOME%/modules/mysql/main
directory; the mysql/main
subdirectory is also to be created. The module.xml file is listed in the following code snippet:<module xmlns="urn:jboss:module:1.1" name="mysql" slot="main"> <resources> <resource-root path="mysql-connector-java-5.1.33-bin.jar"/> </resources> <dependencies> <module name="javax.api"/> </dependencies> </module>
mysql-connector-java-5.1.33-bin.jar
(MySQL JDBC JAR) file from C:Program Files (x86)MySQLConnector.J 5.1
to the %JBOSS_HOME%/modules/mysql/main
directory. The MySQL mysql-connector-java
JAR file version specified in module.xml
must be the same as the version of the JAR file copied to the /modules/mysql/main
directory.<datasource/>
definition for the MySQL database to the <datasources/>
element and a <driver/>
definition to the <drivers/>
element in the %JBOSS_HOME%/standalone/configuration/standalone.xml
file within the <subsystem xmlns="urn:jboss:domain:datasources:2.0">
</subsystem>
element. The <password/>
tag in the <datasource/>
configuration tag is the password configured when the MySQL database is installed. The datasource class for the MySQL driver is a XA
datasource, which is used for distributed transactions:<subsystem xmlns="urn:jboss:domain:datasources:2.0"> <datasources> <datasource jndi-name="java:jboss/datasources/MySQLDS" pool-name="MySQLDS" enabled="true" use-java-context="true"> <connection-url>jdbc:mysql://localhost:3306/test</connection-url> <driver>mysql</driver> <pool> <min-pool-size>10</min-pool-size> <max-pool-size>20</max-pool-size> <prefill>true</prefill> </pool> <security> <user-name>root</user-name> <password>mysql</password> </security> </datasource> <drivers> <driver name="mysql" module="mysql"> <driver-class>com.mysql.jdbc.Driver</driver-class> <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class> </driver> </drivers> </datasources> </subsystem>
C:wildfly-8.1.0.Finalinstandalone
batch file.http://localhost:8080
. Click on Administration Console, as shown in the following screenshot:In the next section, we will create entities for the EJB 3.x application.