Skip to Main Content

Resource not available in @Singleton @Predestroy method

2642681Dec 21 2015

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.

Comments
Post Details
Added on Dec 21 2015
0 comments
524 views