似乎资源不适用于Singleton的@Predestroy方法.
@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(); } }
对getConnection()的调用失败,错误为" No Pool Meta Data object associated with the pool
".请注意,在@PostConstruct方法中,getConnection()调用成功.
它是应用服务器实现中的Bug吗?如果没有,删除临时表的最优雅方法是什么?
(使用Glassfish 4.1.1 + Derby DB.使用与EAR一起部署的glassfish-resources.xml创建数据源
)
更新:
我在GlassFish中创建了一个错误报告https://java.net/jira/browse/GLASSFISH-21476.