Skip to content

Commit 3f31c3d

Browse files
committed
HHH-10293 - Add test for issue
1 parent f9065da commit 3f31c3d

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.schemaupdate.inheritance.hhh_x;
8+
9+
import javax.persistence.DiscriminatorValue;
10+
import javax.persistence.Entity;
11+
import javax.persistence.OneToMany;
12+
import java.util.List;
13+
14+
/**
15+
* @author Andrea Boriero
16+
*/
17+
@DiscriminatorValue("group")
18+
@Entity
19+
public class GroupStep extends Step {
20+
21+
@OneToMany(mappedBy = "parent")
22+
private List<Step> steps;
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.schemaupdate.inheritance.hhh_x;
8+
9+
import org.hibernate.boot.MetadataSources;
10+
import org.hibernate.boot.registry.StandardServiceRegistry;
11+
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
12+
import org.hibernate.boot.spi.MetadataImplementor;
13+
import org.hibernate.tool.hbm2ddl.SchemaExport;
14+
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
15+
import org.hibernate.tool.hbm2ddl.Target;
16+
17+
import org.junit.Test;
18+
19+
/**
20+
* @author Andrea Boriero
21+
*/
22+
public class InheritanceSchemaUpdateTest {
23+
24+
@Test
25+
public void testBidirectionalOneToManyReferencingRootEntity() throws Exception {
26+
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
27+
28+
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
29+
.addAnnotatedClass( Step.class )
30+
.addAnnotatedClass( GroupStep.class )
31+
.buildMetadata();
32+
metadata.validate();
33+
34+
try {
35+
SchemaUpdate su = new SchemaUpdate( ssr, metadata );
36+
su.execute( Target.EXPORT );
37+
}
38+
finally {
39+
SchemaExport schemaExport = new SchemaExport( ssr, metadata );
40+
schemaExport.drop( Target.EXPORT );
41+
StandardServiceRegistryBuilder.destroy( ssr );
42+
}
43+
}
44+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.schemaupdate.inheritance.hhh_x;
8+
9+
import javax.persistence.Column;
10+
import javax.persistence.DiscriminatorColumn;
11+
import javax.persistence.Entity;
12+
import javax.persistence.GeneratedValue;
13+
import javax.persistence.GenerationType;
14+
import javax.persistence.Id;
15+
import javax.persistence.Inheritance;
16+
import javax.persistence.InheritanceType;
17+
import javax.persistence.ManyToOne;
18+
import javax.persistence.Table;
19+
import java.io.Serializable;
20+
21+
/**
22+
* @author Andrea Boriero
23+
*/
24+
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
25+
@DiscriminatorColumn(name = "type")
26+
@Table(name = "step")
27+
@Entity
28+
public abstract class Step implements Serializable {
29+
30+
@Id
31+
@GeneratedValue(strategy = GenerationType.IDENTITY)
32+
@Column(unique = true, nullable = false)
33+
protected Integer id;
34+
35+
@ManyToOne
36+
private Step parent;
37+
}

0 commit comments

Comments
 (0)