Skip to content

Commit add6fc8

Browse files
committed
HHH-10197 - Add test
1 parent 4bb263f commit add6fc8

File tree

4 files changed

+261
-0
lines changed

4 files changed

+261
-0
lines changed
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;
8+
9+
import java.io.Serializable;
10+
import java.util.HashSet;
11+
import java.util.Set;
12+
13+
/**
14+
* @author Andrea Boriero
15+
*/
16+
public class Group implements Serializable {
17+
18+
private String org;
19+
private String name;
20+
private String description;
21+
22+
private Set users = new HashSet();
23+
24+
public Group(String name, String org) {
25+
this.org = org;
26+
this.name = name;
27+
}
28+
29+
public Group() {
30+
}
31+
32+
public String getName() {
33+
return name;
34+
}
35+
36+
public void setName(String name) {
37+
this.name = name;
38+
}
39+
40+
public String getOrg() {
41+
return org;
42+
}
43+
44+
public void setOrg(String org) {
45+
this.org = org;
46+
}
47+
48+
public Set getUsers() {
49+
return users;
50+
}
51+
52+
public void setUsers(Set users) {
53+
this.users = users;
54+
}
55+
56+
public String getDescription() {
57+
return description;
58+
}
59+
60+
public void setDescription(String description) {
61+
this.description = description;
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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;
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.After;
18+
import org.junit.Before;
19+
import org.junit.Test;
20+
21+
import org.hibernate.testing.TestForIssue;
22+
import org.hibernate.testing.junit4.BaseUnitTestCase;
23+
24+
/**
25+
* @author Andrea Boriero
26+
*/
27+
@TestForIssue(jiraKey = "HHH-10197")
28+
public class QuotedTableNameWithForeignKeysSchemaUpdateTest extends BaseUnitTestCase {
29+
30+
@Before
31+
public void setUp() {
32+
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
33+
try {
34+
35+
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
36+
.addResource( "org/hibernate/test/schemaupdate/UserGroup.hbm.xml" )
37+
.buildMetadata();
38+
metadata.validate();
39+
new SchemaUpdate( metadata ).execute( Target.EXPORT );
40+
41+
}
42+
finally {
43+
StandardServiceRegistryBuilder.destroy( ssr );
44+
}
45+
}
46+
47+
@Test
48+
public void testUpdateExistingSchema() {
49+
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
50+
try {
51+
52+
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
53+
.addResource( "org/hibernate/test/schemaupdate/UserGroup.hbm.xml" )
54+
.buildMetadata();
55+
new SchemaUpdate( metadata ).execute( Target.EXPORT );
56+
57+
}
58+
finally {
59+
StandardServiceRegistryBuilder.destroy( ssr );
60+
}
61+
}
62+
63+
@Test
64+
public void testGeneratingUpdateScript() {
65+
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
66+
try {
67+
68+
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
69+
.addResource( "org/hibernate/test/schemaupdate/UserGroup.hbm.xml" )
70+
.buildMetadata();
71+
new SchemaUpdate( metadata ).execute( true, false );
72+
73+
}
74+
finally {
75+
StandardServiceRegistryBuilder.destroy( ssr );
76+
}
77+
}
78+
79+
@After
80+
public void tearDown() {
81+
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
82+
try {
83+
84+
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
85+
.addResource( "org/hibernate/test/schemaupdate/UserGroup.hbm.xml" )
86+
.buildMetadata();
87+
SchemaExport schemaExport = new SchemaExport( ssr, metadata );
88+
schemaExport.drop( true, true );
89+
90+
}
91+
finally {
92+
StandardServiceRegistryBuilder.destroy( ssr );
93+
}
94+
}
95+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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;
8+
9+
import java.io.Serializable;
10+
import java.util.HashSet;
11+
import java.util.Set;
12+
13+
/**
14+
* @author Andrea Boriero
15+
*/
16+
public class User implements Serializable {
17+
18+
private String org;
19+
private String name;
20+
private Set groups = new HashSet();
21+
22+
public User(String name, String org) {
23+
this.org = org;
24+
this.name = name;
25+
}
26+
27+
public User() {
28+
}
29+
30+
public String getName() {
31+
return name;
32+
}
33+
34+
public void setName(String name) {
35+
this.name = name;
36+
}
37+
38+
public String getOrg() {
39+
return org;
40+
}
41+
42+
public void setOrg(String org) {
43+
this.org = org;
44+
}
45+
46+
public Set getGroups() {
47+
return groups;
48+
}
49+
50+
public void setGroups(Set groups) {
51+
this.groups = groups;
52+
}
53+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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
13+
package="org.hibernate.test.schemaupdate">
14+
15+
<class name="org.hibernate.test.schemaupdate.User" table="`User`">
16+
<composite-id>
17+
<key-property name="name"/>
18+
<key-property name="org"/>
19+
</composite-id>
20+
<set name="groups" table="`UserGroup`">
21+
<key>
22+
<column name="userName"/>
23+
<column name="org"/>
24+
</key>
25+
<many-to-many class="org.hibernate.test.schemaupdate.Group">
26+
<column name="groupName"/>
27+
<formula>org</formula>
28+
</many-to-many>
29+
</set>
30+
</class>
31+
32+
<class name="org.hibernate.test.schemaupdate.Group" table="`Group`">
33+
<composite-id>
34+
<key-property name="name"/>
35+
<key-property name="org"/>
36+
</composite-id>
37+
<property name="description"/>
38+
<set name="users" table="`UserGroup`" inverse="true">
39+
<key>
40+
<column name="groupName"/>
41+
<column name="org"/>
42+
</key>
43+
<many-to-many class="org.hibernate.test.schemaupdate.User">
44+
<column name="userName"/>
45+
<formula>org</formula>
46+
</many-to-many>
47+
</set>
48+
</class>
49+
50+
</hibernate-mapping>

0 commit comments

Comments
 (0)