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.