I am trying to migrate an application from Glassfish 3.1.1.2 to Glassfish 4.0. During this process I came up with a problem accessing our database.
It looked like when injecting a jdbc resouce
@Resource(name = "jdbc/MyDBResource")
private DataSource datasource;
Glassfish (or Java) gave me a DataSource pointing to the Derby JDBC pool (which is marked as the default jdbc pool). I found out for this to work on Glassfish 4 I needed to include a glassfish-resource.xml file containing the jdbc pool and jdbc resource definitions. I created the file and added it in one of the project modules:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool
name="MyDBConnectionPool"
res-type="javax.sql.DataSource"
datasource-classname="com.bla.bla.XYZDataSource"
pool-resize-quantity="3"
max-pool-size="200"
steady-pool-size="0"
statement-timeout-in-seconds="20" >
<property name="serverName" value="db.url.com" />
<property name="user" value="scottTheTiger" />
<property name="password" value="theMightyPassword" />
</jdbc-connection-pool>
<jdbc-resource jndi-name="java:module/jdbc/MyDBResource"
pool-name="MyDBConnectionPool"/>
</resources>
I also changed my code to point to the new resource
@Resource(name = "java:module/jdbc/MyDBResource")
private DataSource datasource;
It works fine.
In the present installation (Glassfish 3.1.1.2) the connection pool was defined using the admin console. We sometimes need to tweek the connection pool settings (size, time to live etc) and maybe flush the pool.
I noticed that when I deploy the application, the jdbc pool and resource that I added via the xml file do not show up in the admin console nor does the asadmin list-reource-refs command include them in the results. So if we need to change something in the pool, is there any way to do it without redeploying the whole application?