36
36
import javax .persistence .Table ;
37
37
38
38
import org .hibernate .annotations .GenericGenerator ;
39
- import org .hibernate .cfg .Configuration ;
40
- import org .hibernate .cfg .EJB3NamingStrategy ;
41
- import org .hibernate .cfg .ImprovedNamingStrategy ;
39
+ import org .hibernate .boot .Metadata ;
40
+ import org .hibernate .boot .MetadataSources ;
41
+ import org .hibernate .boot .model .naming .ImplicitNamingStrategyJpaCompliantImpl ;
42
+ import org .hibernate .boot .model .naming .ImplicitNamingStrategyLegacyHbmImpl ;
43
+ import org .hibernate .boot .model .naming .ImplicitNamingStrategyLegacyJpaImpl ;
44
+ import org .hibernate .boot .spi .MetadataImplementor ;
42
45
import org .hibernate .mapping .Collection ;
43
46
import org .hibernate .mapping .Column ;
44
47
import org .hibernate .tool .hbm2ddl .SchemaExport ;
50
53
import static org .junit .Assert .assertEquals ;
51
54
import static org .junit .Assert .assertFalse ;
52
55
import static org .junit .Assert .assertSame ;
53
- import static org .junit .Assert .assertTrue ;
54
56
55
57
/**
56
58
* @author Steve Ebersole
59
61
public class CollectionJoinTableNamingTest extends BaseUnitTestCase {
60
62
@ Test
61
63
@ TestForIssue ( jiraKey = "HHH-9908" )
62
- public void testCollectionJoinTableNamingLegacyStrategy () {
63
- Configuration cfg = new Configuration ();
64
- cfg .setNamingStrategy ( ImprovedNamingStrategy .INSTANCE );
64
+ public void testCollectionJoinTableNamingBase () {
65
+ // really the same as the JPA compliant tests; here we just pick up the default ImplicitNamingStrategy
66
+ final MetadataSources metadataSources = new MetadataSources ();
67
+ metadataSources .addAnnotatedClass ( Input .class );
68
+ metadataSources .addAnnotatedClass ( Ptx .class );
65
69
66
- cfg .addAnnotatedClass ( Input .class );
67
- cfg .addAnnotatedClass ( Ptx .class );
68
- cfg .buildMappings ();
70
+ final Metadata metadata = metadataSources .getMetadataBuilder ()
71
+ .build ();
69
72
70
- Collection inputs1Mapping = cfg .getCollectionMapping ( Ptx .class .getName () + ".inputs1" );
73
+ assertSameTableUsed ( metadata );
74
+ }
75
+
76
+ @ Test
77
+ @ TestForIssue ( jiraKey = "HHH-9908" )
78
+ public void testCollectionJoinTableNamingLegacyJpaStrategy () {
79
+ final MetadataSources metadataSources = new MetadataSources ();
80
+ metadataSources .addAnnotatedClass ( Input .class );
81
+ metadataSources .addAnnotatedClass ( Ptx .class );
82
+
83
+ final Metadata metadata = metadataSources .getMetadataBuilder ()
84
+ .applyImplicitNamingStrategy ( ImplicitNamingStrategyLegacyJpaImpl .INSTANCE )
85
+ .build ();
86
+
87
+ assertSameTableUsed ( metadata );
88
+ }
89
+
90
+ @ Test
91
+ @ TestForIssue ( jiraKey = "HHH-9908" )
92
+ public void testCollectionJoinTableNamingLegacyHbmStrategy () {
93
+ final MetadataSources metadataSources = new MetadataSources ();
94
+ metadataSources .addAnnotatedClass ( Input .class );
95
+ metadataSources .addAnnotatedClass ( Ptx .class );
96
+
97
+ final Metadata metadata = metadataSources .getMetadataBuilder ()
98
+ .applyImplicitNamingStrategy ( ImplicitNamingStrategyLegacyHbmImpl .INSTANCE )
99
+ .build ();
100
+
101
+ Collection inputs1Mapping = metadata .getCollectionBinding ( Ptx .class .getName () + ".inputs1" );
71
102
assertEquals ( "ptx_inputs1" , inputs1Mapping .getCollectionTable ().getName () );
72
103
73
- Collection inputs2Mapping = cfg . getCollectionMapping ( Ptx .class .getName () + ".inputs2" );
104
+ Collection inputs2Mapping = metadata . getCollectionBinding ( Ptx .class .getName () + ".inputs2" );
74
105
assertEquals ( "ptx_inputs2" , inputs2Mapping .getCollectionTable ().getName () );
75
106
}
76
107
@@ -79,22 +110,28 @@ public void testCollectionJoinTableNamingLegacyStrategy() {
79
110
public void testCollectionJoinTableNamingJpaCompliantStrategy () {
80
111
// Even in 4.3, with JPA compliant naming, Hibernate creates an unusable table...
81
112
82
- Configuration cfg = new Configuration ();
83
- cfg .setNamingStrategy ( EJB3NamingStrategy .INSTANCE );
113
+ final MetadataSources metadataSources = new MetadataSources ();
114
+ metadataSources .addAnnotatedClass ( Input .class );
115
+ metadataSources .addAnnotatedClass ( Ptx .class );
116
+
117
+ final Metadata metadata = metadataSources .getMetadataBuilder ()
118
+ .applyImplicitNamingStrategy ( ImplicitNamingStrategyJpaCompliantImpl .INSTANCE )
119
+ .build ();
84
120
85
- cfg .addAnnotatedClass ( Input .class );
86
- cfg .addAnnotatedClass ( Ptx .class );
87
- cfg .buildMappings ();
121
+ assertSameTableUsed ( metadata );
122
+ }
88
123
89
- Collection inputs1Mapping = cfg .getCollectionMapping ( Ptx .class .getName () + ".inputs1" );
124
+ private void assertSameTableUsed (Metadata metadata ) {
125
+ Collection inputs1Mapping = metadata .getCollectionBinding ( Ptx .class .getName () + ".inputs1" );
90
126
assertEquals ( "ptx_input" , inputs1Mapping .getCollectionTable ().getName () );
91
127
92
- Collection inputs2Mapping = cfg . getCollectionMapping ( Ptx .class .getName () + ".inputs2" );
128
+ Collection inputs2Mapping = metadata . getCollectionBinding ( Ptx .class .getName () + ".inputs2" );
93
129
assertEquals ( "ptx_input" , inputs2Mapping .getCollectionTable ().getName () );
94
130
95
131
assertSame ( inputs1Mapping .getCollectionTable (), inputs2Mapping .getCollectionTable () );
96
132
97
- new SchemaExport ( cfg ).create ( true , false );
133
+ // NOTE : here so that tester can more easily see the produced table. It is only dumped to stdout
134
+ new SchemaExport ( (MetadataImplementor ) metadata ).create ( true , false );
98
135
99
136
for ( int i = 0 ; i < inputs1Mapping .getCollectionTable ().getColumnSpan (); i ++ ) {
100
137
final Column column = inputs1Mapping .getCollectionTable ().getColumn ( i );
0 commit comments