Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,19 @@ public IdentityColumnSupport getIdentityColumnSupport() {
return DB2IdentityColumnSupport.INSTANCE;
}

/**
* @return {@code true} because we can use {@code select ... from new table (insert .... )}
*/
@Override
public boolean supportsInsertReturning() {
return true;
}

@Override
public boolean supportsInsertReturningRowId() {
return false;
}

@Override
public boolean supportsValuesList() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
*/
package org.hibernate.id;

import java.util.List;

import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.id.insert.BasicSelectingDelegate;
import org.hibernate.id.insert.GetGeneratedKeysDelegate;
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
import org.hibernate.id.insert.InsertReturningDelegate;
import org.hibernate.id.insert.UniqueKeySelectingDelegate;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.persister.entity.EntityPersister;

import static org.hibernate.generator.EventType.INSERT;
Expand Down Expand Up @@ -52,11 +54,16 @@ public String[] getReferencedColumnValues(Dialect dialect) {

@Override
public InsertGeneratedIdentifierDelegate getGeneratedIdentifierDelegate(EntityPersister persister) {
final SessionFactoryImplementor factory = persister.getFactory();
final Dialect dialect = factory.getJdbcServices().getDialect();
final Dialect dialect = persister.getFactory().getJdbcServices().getDialect();
final SessionFactoryOptions sessionFactoryOptions = persister.getFactory().getSessionFactoryOptions();
final List<? extends ModelPart> generatedProperties = persister.getGeneratedProperties( INSERT );
if ( generatedProperties.size() == 1 && sessionFactoryOptions.isGetGeneratedKeysEnabled() ) {
// Use Connection#prepareStatement(sql, Statement.RETURN_GENERATED_KEYS) when only retrieving identity
assert generatedProperties.get( 0 ).isEntityIdentifierMapping();
return dialect.getIdentityColumnSupport().buildGetGeneratedKeysDelegate( persister );
}
// Try to use generic delegates if the dialects supports them
final SessionFactoryOptions sessionFactoryOptions = factory.getSessionFactoryOptions();
if ( dialect.supportsInsertReturningGeneratedKeys() && sessionFactoryOptions.isGetGeneratedKeysEnabled() ) {
else if ( dialect.supportsInsertReturningGeneratedKeys() && sessionFactoryOptions.isGetGeneratedKeysEnabled() ) {
return new GetGeneratedKeysDelegate( persister, false, INSERT );
}
else if ( dialect.supportsInsertReturning() && noCustomSql( persister, INSERT ) ) {
Expand Down
Loading