HHH-12968 - Flush is not flushing inserts for inherited tables before a select within a transaction

Extract IdentityGenerator batch support validation logic

(cherry picked from commit f21c8c2927)
This commit is contained in:
Vlad Mihalcea 2018-09-24 20:40:37 +03:00 committed by gbadner
parent fd186a1dd5
commit 59ad417498
3 changed files with 17 additions and 3 deletions

View File

@ -32,4 +32,9 @@ public abstract class AbstractPostInsertGenerator
public String determineBulkInsertionIdentifierGenerationSelectFragment(Dialect dialect) { public String determineBulkInsertionIdentifierGenerationSelectFragment(Dialect dialect) {
return null; return null;
} }
@Override
public boolean supportsJdbcBatchInserts() {
return false;
}
} }

View File

@ -7,7 +7,6 @@
package org.hibernate.id; package org.hibernate.id;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
@ -60,4 +59,13 @@ public interface IdentifierGenerator {
* @throws HibernateException Indicates trouble generating the identifier * @throws HibernateException Indicates trouble generating the identifier
*/ */
Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException; Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException;
/**
* Check if JDBC batch inserts are supported.
*
* @return JDBC batch inserts are supported.
*/
default boolean supportsJdbcBatchInserts() {
return true;
}
} }

View File

@ -83,7 +83,6 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.ValueInclusion; import org.hibernate.engine.spi.ValueInclusion;
import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.IdentityGenerator;
import org.hibernate.id.PostInsertIdentifierGenerator; import org.hibernate.id.PostInsertIdentifierGenerator;
import org.hibernate.id.PostInsertIdentityPersister; import org.hibernate.id.PostInsertIdentityPersister;
import org.hibernate.id.insert.Binder; import org.hibernate.id.insert.Binder;
@ -3146,7 +3145,9 @@ public abstract class AbstractEntityPersister
// TODO : shouldn't inserts be Expectations.NONE? // TODO : shouldn't inserts be Expectations.NONE?
final Expectation expectation = Expectations.appropriateExpectation( insertResultCheckStyles[j] ); final Expectation expectation = Expectations.appropriateExpectation( insertResultCheckStyles[j] );
final int jdbcBatchSizeToUse = session.getConfiguredJdbcBatchSize(); final int jdbcBatchSizeToUse = session.getConfiguredJdbcBatchSize();
final boolean useBatch = expectation.canBeBatched() && jdbcBatchSizeToUse > 1 && !( getIdentifierGenerator() instanceof IdentityGenerator ); final boolean useBatch = expectation.canBeBatched() &&
jdbcBatchSizeToUse > 1 &&
getIdentifierGenerator().supportsJdbcBatchInserts();
if ( useBatch && inserBatchKey == null ) { if ( useBatch && inserBatchKey == null ) {
inserBatchKey = new BasicBatchKey( inserBatchKey = new BasicBatchKey(