Skip to content

Commit a9e4eb4

Browse files
dreab8sebersole
authored andcommitted
HHH-10373 - Add test for issue
1 parent 3cb2390 commit a9e4eb4

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.idbag;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
/**
13+
* @author Andrea Boriero
14+
*/
15+
public class IdBagOwner {
16+
private long id;
17+
private List<IdBagOwner> children = new ArrayList<IdBagOwner>();
18+
19+
public long getId() {
20+
return id;
21+
}
22+
23+
public void setId(long id) {
24+
this.id = id;
25+
}
26+
27+
public List<IdBagOwner> getChildren() {
28+
return children;
29+
}
30+
31+
public void setChildren(List<IdBagOwner> children) {
32+
this.children = children;
33+
}
34+
35+
public void addChild(IdBagOwner child){
36+
children.add( child );
37+
}
38+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.idbag;
8+
9+
import java.io.File;
10+
import java.nio.file.Files;
11+
import java.util.EnumSet;
12+
13+
import org.hibernate.boot.MetadataSources;
14+
import org.hibernate.boot.registry.StandardServiceRegistry;
15+
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
16+
import org.hibernate.boot.spi.MetadataImplementor;
17+
import org.hibernate.cfg.Environment;
18+
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
19+
import org.hibernate.tool.schema.TargetType;
20+
21+
import org.junit.Test;
22+
23+
import org.hibernate.testing.TestForIssue;
24+
25+
import static org.hamcrest.core.Is.is;
26+
import static org.junit.Assert.assertThat;
27+
28+
/**
29+
* @author Andrea Boriero
30+
*/
31+
@TestForIssue(jiraKey = "HHH-10373")
32+
public class IdBagSequenceTest {
33+
34+
@Test
35+
public void testIdBagSequenceGeneratorIsCreated() throws Exception {
36+
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
37+
.applySetting( Environment.HBM2DDL_AUTO, "none" )
38+
.build();
39+
try {
40+
File output = File.createTempFile( "update_script", ".sql" );
41+
output.deleteOnExit();
42+
43+
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
44+
.addResource( "org/hibernate/test/schemaupdate/idbag/Mappings.hbm.xml" )
45+
.buildMetadata();
46+
metadata.validate();
47+
48+
new SchemaUpdate()
49+
.setHaltOnError( true )
50+
.setOutputFile( output.getAbsolutePath() )
51+
.setDelimiter( ";" )
52+
.setFormat( true )
53+
.execute( EnumSet.of( TargetType.SCRIPT ), metadata );
54+
55+
String fileContent = new String( Files.readAllBytes( output.toPath() ) );
56+
assertThat( fileContent.toLowerCase().contains( "create sequence seq_child_id" ), is( true ) );
57+
}
58+
finally {
59+
StandardServiceRegistryBuilder.destroy( ssr );
60+
}
61+
}
62+
63+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ Hibernate, Relational Persistence for Idiomatic Java
4+
~
5+
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
6+
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
7+
-->
8+
<!DOCTYPE hibernate-mapping PUBLIC
9+
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
10+
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
11+
12+
<hibernate-mapping package="org.hibernate.test.schemaupdate.idbag">
13+
14+
<class name="org.hibernate.test.schemaupdate.idbag.IdBagOwner">
15+
<id name="id" column="id">
16+
<generator class="sequence">
17+
<param name="sequence_name">seq_owner_id</param>
18+
</generator>
19+
</id>
20+
21+
<idbag name="children" cascade="all" table="idbag_owner_children">
22+
<collection-id type="long" column="id">
23+
<generator class="sequence">
24+
<param name="sequence_name">seq_child_id</param>
25+
</generator>
26+
</collection-id>
27+
<key column="PARENT_FK"/>
28+
<many-to-many column="CHILD_FK" class="org.hibernate.test.schemaupdate.idbag.IdBagOwner"/>
29+
</idbag>
30+
</class>
31+
32+
</hibernate-mapping>

0 commit comments

Comments
 (0)