It seems like resources are not available to a Singleton's @Predestroy method.
@PreDestroy
public void cleanup() {
logger.info("*** Application shutting down. Dropping temporary tables ***");
try {
connection = dataSource.getConnection();
Statement statement = connection.createStatement();
statement.execute("drop table TABLE1");
statement.execute("drop table TABLE2");
connection.close();
connection = null;
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
The call to getConnection() fails with the error "No Pool Meta Data object associated with the pool
". Note that the getConnection() call is successful in the @PostConstruct methods.
Is it a Bug in the application server implementation? If not, what is the most elegant way to drop temporary tables?
(Using Glassfish 4.1.1 + Derby DB. The datasource is created using glassfish-resources.xml deployed with the EAR
<resources>
<jdbc-resource pool-name="EmbeddedDerbyPool"
jndi-name="java:app/jdbc/ActionBazaarDS" />
<jdbc-connection-pool name="EmbeddedDerbyPool"
res-type="javax.sql.DataSource"
datasource-classname="org.apache.derby.jdbc.EmbeddedDataSource"
is-isolation-level-guaranteed="false">
<property name="databaseName" value="memory:action-bazaar-db"/>
<property name="createDatabase" value="create"/>
</jdbc-connection-pool>
</resources>
)
Update:
I created a bug report in GlassFish https://java.net/jira/browse/GLASSFISH-21476.