HHH-10293 - Add test for issue

This commit is contained in:
Andrea Boriero 2015-11-15 16:00:42 +00:00
parent f9065daba1
commit 3f31c3d79f
3 changed files with 104 additions and 0 deletions

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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<Step> steps;
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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 );
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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;
}