Changeset 7397


Ignore:
Timestamp:
Jun 16, 2017, 2:02:22 PM (5 years ago)
Author:
Nicklas Nordborg
Message:

References #2048: Upgrade to Hibernate 5.2

The database schema generator need to pass the supplied connection to the Hibernate tools (using the "javax.persistence.schema-generation-connection" configuration setting). If not, they will open a new connection. Under some circumstances this fails when used with extensions that via the "services" extension point try to initiate their own database schema and tables.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/hibernate/SchemaGenerator.java

    r7391 r7397  
    2929import java.util.Collections;
    3030import java.util.EnumSet;
     31import java.util.HashMap;
    3132import java.util.List;
    3233import java.util.Map;
     
    129130    Statement stmt = connection.createStatement();
    130131    String currentSql = null;
     132    boolean autoCommit = connection.getAutoCommit();
    131133    ForceQuotedTableNameFormatter tableNameFormatter = new ForceQuotedTableNameFormatter(metadata);
    132134    try
    133135    {
    134       final CollectSqlTarget schemaUpdates = new CollectSqlTarget(dbEngine, dialect, mode);
     136      final CollectSqlTarget schemaUpdates = new CollectSqlTarget(dbEngine, dialect, mode, connection);
    135137      final CollectSqlTarget indexUpdates = new CollectSqlTarget();
    136138     
     
    220222    finally
    221223    {
     224      if (autoCommit != connection.getAutoCommit()) connection.setAutoCommit(autoCommit);
    222225      tableNameFormatter.resetWorkaroundForHibernateBug();
    223226      if (stmt != null)
     
    257260    private final Dialect dialect;
    258261    private final DbEngine dbEngine;
     262    private final Map<Object, Object> config;
    259263    private final Mode mode;
    260264    private int numStatements;
     
    262266    CollectSqlTarget()
    263267    {
    264       this(null, null, null);
    265     }
    266    
    267     CollectSqlTarget(DbEngine dbEngine, Dialect dialect, Mode mode)
     268      this(null, null, null, null);
     269    }
     270   
     271    CollectSqlTarget(DbEngine dbEngine, Dialect dialect, Mode mode, Connection connection)
    268272    {
    269273      this.dbEngine = dbEngine;
    270274      this.dialect = dialect;
    271275      this.mode = mode;
     276      // The supplied connection is passed on to Hibernate tools via the "javax...." configuration setting
     277      Map<Object, Object> tmp = new HashMap<>();
     278      if (connection != null) tmp.put("javax.persistence.schema-generation-connection", connection);
     279      this.config = Collections.unmodifiableMap(tmp);
    272280      this.allSql = new ArrayList<SqlStatement>();
    273281      this.numStatements = 0;
     
    327335    public Map<?, ?> getConfigurationValues()
    328336    {
    329       return Collections.emptyMap();
     337      return config;
    330338    }
    331339
Note: See TracChangeset for help on using the changeset viewer.