本文介绍了如何禁用休眠4临时表休闲?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当我连接到数据库时,Hibernate 4都会创建临时表, Hibernate:create table HT _... ..
有没有办法一次创建它们?
解决方案
我明白目的,但问题在于我的情况,当用户选择相同的数据库时,需要10次后台才能重新创建所有临时表,这里如何避免:
i添加这部分
if(e.toString()。contains(already exists ))/ *********临时表存在,我们应该打破******** /
break;
到类org.hibernate.hql.spi.PersistentTableBulkIdStrategy
protected void exportTableDefinitions(
List< Table> idTableDefinitions,
JdbcServices jdbcServices,
JdbcConnectionAccess connectionAccess,
Mappings mappings,
映射映射){
尝试{
连接连接;
尝试{
connection = connectionAccess.obtainConnection();
catch(UnsupportedOperationException e){
//假设这来自org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl
log.debug(Unable to obtain JDBC连接;假设ID表已经存在或不需要);
return;
}
try {
// TODO:session.getTransactionCoordinator()。getJdbcCoordinator()。getStatementPreparer()。createStatement();
Statement statement = connection.createStatement();
for(Table idTableDefinition:idTableDefinitions){
if(cleanUpTables){
if(tableCleanUpDdl == null){
tableCleanUpDdl = new ArrayList< String>();
}
tableCleanUpDdl.add(idTableDefinition.sqlDropString(jdbcServices.getDialect(),null,null));
try {
final String sql = idTableDefinition.sqlCreateString(jdbcServices.getDialect(),mapping,null,null);
jdbcServices.getSqlStatementLogger()。logStatement(sql);
// TODO:ResultSetExtractor
statement.execute(sql);
catch(SQLException e){
if(e.toString()。contains(already exists))/ *********临时表存在我们应该休息******** /
休息;
log.debugf(尝试导出id-table [%s]时出错:%s,idTableDefinition.getName(),e.getMessage());
$ b $ // TODO
// session.getTransactionCoordinator()。getJdbcCoordinator()。release(statement);
statement.close();
catch(SQLException e){
log.error(无法使用JDBC连接创建语句,e);
}
finally {
try {
connectionAccess.releaseConnection(connection);
catch(SQLException ignore){
}
}
}
catch(SQLException e){
log.error(Unable获取JDBC连接,e);
}
}
Hibernate 4 is creating the temporary tables every time i connect to the database,
Hibernate: create table HT_.....
is there a way to create them once time only ?
解决方案
I do understand the purpose, but the problem is in my case, when the user select the same DB, it takes 10 secondes to recreate all temporary tables, so here how to avoid that :i add this part
if (e.toString().contains("already exists")) /********* temporary tables exists we should break ********/
break;
to the Class org.hibernate.hql.spi.PersistentTableBulkIdStrategy
protected void exportTableDefinitions(
List<Table> idTableDefinitions,
JdbcServices jdbcServices,
JdbcConnectionAccess connectionAccess,
Mappings mappings,
Mapping mapping) {
try {
Connection connection;
try {
connection = connectionAccess.obtainConnection();
}
catch (UnsupportedOperationException e) {
// assume this comes from org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl
log.debug( "Unable to obtain JDBC connection; assuming ID tables already exist or wont be needed" );
return;
}
try {
// TODO: session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().createStatement();
Statement statement = connection.createStatement();
for ( Table idTableDefinition : idTableDefinitions ) {
if ( cleanUpTables ) {
if ( tableCleanUpDdl == null ) {
tableCleanUpDdl = new ArrayList<String>();
}
tableCleanUpDdl.add( idTableDefinition.sqlDropString( jdbcServices.getDialect(), null, null ) );
}
try {
final String sql = idTableDefinition.sqlCreateString( jdbcServices.getDialect(), mapping, null, null );
jdbcServices.getSqlStatementLogger().logStatement( sql );
// TODO: ResultSetExtractor
statement.execute( sql );
}
catch (SQLException e) {
if (e.toString().contains("already exists")) /********* temporary tables exists we should break ********/
break;
log.debugf( "Error attempting to export id-table [%s] : %s", idTableDefinition.getName(), e.getMessage() );
}
}
// TODO
// session.getTransactionCoordinator().getJdbcCoordinator().release( statement );
statement.close();
}
catch (SQLException e) {
log.error( "Unable to use JDBC Connection to create Statement", e );
}
finally {
try {
connectionAccess.releaseConnection( connection );
}
catch (SQLException ignore) {
}
}
}
catch (SQLException e) {
log.error( "Unable obtain JDBC Connection", e );
}
}
这篇关于如何禁用休眠4临时表休闲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!