We use Tomcat DBCP with validation query, db2jcc4.jar and DB2 v11 z/OS
While testing the migration from Hibernate 3.3.2 to Hibernate 5.0.2 we had mysterious (non-deterministic) SQLErrors:
org.hibernate.engine.jdbc.spi.SqlExceptionHelper - [jcc][t4][2030][11211][4.14.137] Bei Operationen auf dem der Verbindung zugrunde liegendem Socket, im Socketeingabedatenstrom oder Socketausgabedatenstrom ist ein Kommunikationsfehler aufgetreten. Fehlerposition: T4Agent.sendRequest() - flush (-1). Nachricht: Connection reset. ERRORCODE=-4499, SQLSTATE=08001
Our db2 admins analyzed their db2 logfiles. They said the following statement causes the problem:
DECLARE GLOBAL TEMPORARY TABLE ... NOT LOGGED
This statement is defined in DB2Dialect (we use DB2390Dialect).
This statement creates db2-threads that hold locks for some minutes until they are killed.
The db2 documentation says an explicit DROP TABLE statement must follow or the DECLARE statement has to be defined with ON COMMIT DROP TABLE clause.
My solution:
Code:
public class MyTemporaryTableBulkIdStrategy extends GlobalTemporaryTableBulkIdStrategy {
public MyTemporaryTableBulkIdStrategy() {
super(new IdTableSupportStandardImpl() {
@Override
public String generateIdTableName(String baseName) {
return "session." + super.generateIdTableName(baseName);
}
@Override
public String getCreateIdTableCommand() {
return "declare global temporary table";
}
@Override
public String getCreateIdTableStatementOptions() {
return "not logged on commit drop table";
}
}, AfterUseAction.CLEAN);
}
and configuration in persistence.xml via property:
<property name="hibernate.hql.bulk_id_strategy" value="...MyTemporaryTableBulkIdStrategy" />
My questions:
- Do you think this is the correct solution oder do you recommend another solution?
- Why doesn't Hibernate use the "ON COMMIT DROP TABLE" clause (at least within DB2390Dialect)?
Thank you for any hints!