mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-26 13:25:19 +00:00
HHH-18809 auto-disable use of getGeneratedKeys() when there is a @Formula
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
fc1d0f5456
commit
e4b52c2cf1
@ -27,6 +27,7 @@
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
|
||||
import org.hibernate.metamodel.mapping.ModelPart;
|
||||
import org.hibernate.metamodel.mapping.SelectableMapping;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.persister.entity.mutation.EntityTableMapping;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
@ -326,7 +327,11 @@ private static List<? extends ModelPart> getActualGeneratedModelParts(
|
||||
public static GeneratedValuesMutationDelegate getGeneratedValuesDelegate(
|
||||
EntityPersister persister,
|
||||
EventType timing) {
|
||||
final boolean hasGeneratedProperties = !persister.getGeneratedProperties( timing ).isEmpty();
|
||||
final List<? extends ModelPart> generatedProperties = persister.getGeneratedProperties( timing );
|
||||
final boolean hasGeneratedProperties = !generatedProperties.isEmpty();
|
||||
final boolean hasFormula =
|
||||
generatedProperties.stream()
|
||||
.anyMatch( part -> part instanceof SelectableMapping selectable && selectable.isFormula() );
|
||||
final boolean hasRowId = timing == EventType.INSERT && persister.getRowIdMapping() != null;
|
||||
final Dialect dialect = persister.getFactory().getJdbcServices().getDialect();
|
||||
|
||||
@ -341,7 +346,8 @@ && noCustomSql( persister, timing ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( dialect.supportsInsertReturningGeneratedKeys()
|
||||
if ( !hasFormula
|
||||
&& dialect.supportsInsertReturningGeneratedKeys()
|
||||
&& persister.getFactory().getSessionFactoryOptions().isGetGeneratedKeysEnabled() ) {
|
||||
return new GetGeneratedKeysDelegate( persister, false, timing );
|
||||
}
|
||||
|
@ -9,16 +9,13 @@
|
||||
import org.hibernate.annotations.Formula;
|
||||
import org.hibernate.annotations.Generated;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static org.hibernate.cfg.JdbcSettings.USE_GET_GENERATED_KEYS;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
@ -27,7 +24,7 @@
|
||||
@SuppressWarnings("JUnitMalformedDeclaration")
|
||||
@DomainModel(annotatedClasses = FormulaGeneratedTest.OrderLine.class)
|
||||
@SessionFactory
|
||||
@ServiceRegistry(settings = @Setting(name = USE_GET_GENERATED_KEYS, value = "false"))
|
||||
//@ServiceRegistry(settings = @Setting(name = USE_GET_GENERATED_KEYS, value = "false"))
|
||||
public class FormulaGeneratedTest {
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user