From a7f079aed350fb94ee4dee6abbd9d91928eff6a5 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Tue, 19 Apr 2016 13:39:11 +0100 Subject: [PATCH] HHH-10373 - Add test for issue (cherry picked from commit a9e4eb489516bc67c054ca5d10c00a2723c7f7cf) --- .../test/schemaupdate/idbag/IdBagOwner.java | 38 +++++++++++ .../schemaupdate/idbag/IdBagSequenceTest.java | 63 +++++++++++++++++++ .../test/schemaupdate/idbag/Mappings.hbm.xml | 32 ++++++++++ 3 files changed, 133 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/IdBagOwner.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/IdBagSequenceTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/Mappings.hbm.xml diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/IdBagOwner.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/IdBagOwner.java new file mode 100644 index 0000000000..7463ef4757 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/IdBagOwner.java @@ -0,0 +1,38 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.schemaupdate.idbag; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Andrea Boriero + */ +public class IdBagOwner { + private long id; + private List children = new ArrayList(); + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + public void addChild(IdBagOwner child){ + children.add( child ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/IdBagSequenceTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/IdBagSequenceTest.java new file mode 100644 index 0000000000..f6731bb162 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/IdBagSequenceTest.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.schemaupdate.idbag; + +import java.io.File; +import java.nio.file.Files; +import java.util.EnumSet; + +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.cfg.Environment; +import org.hibernate.tool.hbm2ddl.SchemaUpdate; +import org.hibernate.tool.schema.TargetType; + +import org.junit.Test; + +import org.hibernate.testing.TestForIssue; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +/** + * @author Andrea Boriero + */ +@TestForIssue(jiraKey = "HHH-10373") +public class IdBagSequenceTest { + + @Test + public void testIdBagSequenceGeneratorIsCreated() throws Exception { + StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() + .applySetting( Environment.HBM2DDL_AUTO, "none" ) + .build(); + try { + File output = File.createTempFile( "update_script", ".sql" ); + output.deleteOnExit(); + + final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) + .addResource( "org/hibernate/test/schemaupdate/idbag/Mappings.hbm.xml" ) + .buildMetadata(); + metadata.validate(); + + new SchemaUpdate() + .setHaltOnError( true ) + .setOutputFile( output.getAbsolutePath() ) + .setDelimiter( ";" ) + .setFormat( true ) + .execute( EnumSet.of( TargetType.SCRIPT ), metadata ); + + String fileContent = new String( Files.readAllBytes( output.toPath() ) ); + assertThat( fileContent.toLowerCase().contains( "create sequence seq_child_id" ), is( true ) ); + } + finally { + StandardServiceRegistryBuilder.destroy( ssr ); + } + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/Mappings.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/Mappings.hbm.xml new file mode 100644 index 0000000000..b8a587ef15 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/Mappings.hbm.xml @@ -0,0 +1,32 @@ + + + + + + + + + + seq_owner_id + + + + + + + seq_child_id + + + + + + + + \ No newline at end of file