JBoss.orgCommunity Documentation

FAQs of database configuration

Q1. How to configure eXo Platform to connect to other database systems?

Configuring eXo Platform to connect to other database can be done easily. eXo Platform provides sample configuration files in the folders:

In each folder, you will find two sample xml files: gatein-ds.xml for JBoss and server.xml for Tomcat.

Each file contains 2 preconfigured datasources. For example (JCR datasource in mysql/server.xml):

<Resource name="exo-jcr_portal" auth="Container" type="javax.sql.DataSource"
          maxActive="128" maxIdle="32" maxWait="10000"
          testWhileIdle="true" timeBetweenEvictionRunsMillis="30000" validationQuery="SELECT 1" 
          username="${db.username}" password="${db.password}" driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://${db.host}:${db.port}/${db.jcr.name}"/>

You simply replace the variables with the expected values:

Variables Expected values
db.username The username that connects to the database.
db.password The password for the above user.
db.host The hostname or IP address of the DB server.
db.port The port to connect to the DB.
db.jcr.name The DB name for the JCR datasource.
db.idm.name The DB name for the IDM datasource.

Please remember to add the JDBC connector JAR in the classpath of your application server.

You can download the official JDBC connector JARs from the following websites:

Q2. How to remove the idle MySQL connections?

Some RDBMSs, like MySQL, close the idle connections after a period (8 hours on MySQL by default). Thus, a connection from the pool will be invalid and any application SQL command will fail, resulting in errors as below:

org.hibernate.SessionException: Session is closed!
at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:72)
at org.hibernate.impl.SessionImpl.getTransaction(SessionImpl.java:1342)

To avoid this, you can use DBCP to monitor the idle connections and drop them when they are invalid, with the parameters testWhileIdle, timeBetweenEvictionRunsMillis and validationQuery.

The validation query is specific to your RDBMS. For example, on MySQL, you would use:

testWhileIdle="true" timeBetweenEvictionRunsMillis="30000" validationQuery="SELECT 1"

In which:

You can add these parameters to the data source configuration file of your application server, for example: conf/server.xml on Tomcat.

For more details on the configuration, or some examples on other RDBMS and applications servers, please refer to:

Q3. How to enable managed DataSource?

When you want to use a managed data source (which is the case under JBoss), set "true" for the gatein.jcr.datasource.managed property in the configuration.properties file

# indicates if the jcr datasource is using managed transactions. 
# false by default. 
gatein.jcr.datasource.managed=true