diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/inheritance/hhh_x/GroupStep.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/inheritance/hhh_x/GroupStep.java new file mode 100644 index 0000000000..e5c92d99ba --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/inheritance/hhh_x/GroupStep.java @@ -0,0 +1,23 @@ +/* + * 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.inheritance.hhh_x; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; +import javax.persistence.OneToMany; +import java.util.List; + +/** + * @author Andrea Boriero + */ +@DiscriminatorValue("group") +@Entity +public class GroupStep extends Step { + + @OneToMany(mappedBy = "parent") + private List steps; +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/inheritance/hhh_x/InheritanceSchemaUpdateTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/inheritance/hhh_x/InheritanceSchemaUpdateTest.java new file mode 100644 index 0000000000..e23eed699b --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/inheritance/hhh_x/InheritanceSchemaUpdateTest.java @@ -0,0 +1,44 @@ +/* + * 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.inheritance.hhh_x; + +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.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.hbm2ddl.SchemaUpdate; +import org.hibernate.tool.hbm2ddl.Target; + +import org.junit.Test; + +/** + * @author Andrea Boriero + */ +public class InheritanceSchemaUpdateTest { + + @Test + public void testBidirectionalOneToManyReferencingRootEntity() throws Exception { + StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); + + MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) + .addAnnotatedClass( Step.class ) + .addAnnotatedClass( GroupStep.class ) + .buildMetadata(); + metadata.validate(); + + try { + SchemaUpdate su = new SchemaUpdate( ssr, metadata ); + su.execute( Target.EXPORT ); + } + finally { + SchemaExport schemaExport = new SchemaExport( ssr, metadata ); + schemaExport.drop( Target.EXPORT ); + StandardServiceRegistryBuilder.destroy( ssr ); + } + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/inheritance/hhh_x/Step.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/inheritance/hhh_x/Step.java new file mode 100644 index 0000000000..e01d1062de --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/inheritance/hhh_x/Step.java @@ -0,0 +1,37 @@ +/* + * 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.inheritance.hhh_x; + +import javax.persistence.Column; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import java.io.Serializable; + +/** + * @author Andrea Boriero + */ +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "type") +@Table(name = "step") +@Entity +public abstract class Step implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(unique = true, nullable = false) + protected Integer id; + + @ManyToOne + private Step parent; +}