From 86ba5144f6c993382c3c04e8149b9dfb3152202c Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Fri, 16 Dec 2022 17:47:00 +0100 Subject: [PATCH] HHH-15900 Add test for issue --- .../select/SelectGeneratorTest.java | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/select/SelectGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/select/SelectGeneratorTest.java index 4aa386b3da..2cf37a1367 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/select/SelectGeneratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/select/SelectGeneratorTest.java @@ -6,19 +6,28 @@ */ package org.hibernate.orm.test.generatedkeys.select; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.EnumSet; + import org.hibernate.dialect.OracleDialect; +import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.schema.TargetType; import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.RequiresDialect; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; - import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; /** * @author Steve Ebersole + * @author Marco Belladelli */ @DomainModel( xmlMappings = "org/hibernate/orm/test/generatedkeys/select/MyEntity.hbm.xml" @@ -32,13 +41,31 @@ public class SelectGeneratorTest { scope.inTransaction( session -> { MyEntity e = new MyEntity( "entity-1" ); - session.save( e ); + session.persist( e ); // this insert should happen immediately! - assertEquals( new Long(1), e.getId(), "id not generated through forced insertion" ); + assertEquals( Long.valueOf( 1L ), e.getId(), "id not generated through forced insertion" ); - session.delete( e ); + session.remove( e ); } ); } + + @Test + @JiraKey("HHH-15900") + public void testGeneratedKeyNotIdentityColumn(SessionFactoryScope scope) throws IOException { + File output = File.createTempFile( "schema_export", ".sql" ); + output.deleteOnExit(); + + final SchemaExport schemaExport = new SchemaExport(); + schemaExport.setOutputFile( output.getAbsolutePath() ); + schemaExport.execute( + EnumSet.of( TargetType.SCRIPT ), + SchemaExport.Action.CREATE, + scope.getMetadataImplementor() + ); + + String fileContent = new String( Files.readAllBytes( output.toPath() ) ); + assertFalse( fileContent.toLowerCase().contains( "identity" ), "Column was generated as identity" ); + } }