13
13
import org .hibernate .boot .Metadata ;
14
14
import org .hibernate .boot .MetadataSources ;
15
15
import org .hibernate .boot .SessionFactoryBuilder ;
16
- import org .hibernate .cache .internal .CacheKeyImplementation ;
17
16
import org .hibernate .cache .internal .DefaultCacheKeysFactory ;
18
17
import org .hibernate .engine .spi .SessionFactoryImplementor ;
19
18
import org .hibernate .persister .entity .EntityPersister ;
24
23
import org .junit .Test ;
25
24
26
25
import static org .junit .Assert .assertFalse ;
26
+ import static org .junit .Assert .assertTrue ;
27
27
28
28
/**
29
29
* @author Gail Badner
@@ -32,37 +32,74 @@ public class CacheKeyImplementationHashCodeTest {
32
32
33
33
@ Test
34
34
@ JiraKey ( value = "HHH-12746" )
35
- public void test () {
35
+ public void testHashCodeChanges () {
36
36
try (ServiceRegistryImplementor serviceRegistry = ServiceRegistryUtil .serviceRegistry ()) {
37
37
MetadataSources ms = new MetadataSources ( serviceRegistry );
38
38
ms .addAnnotatedClass ( AnEntity .class ).addAnnotatedClass ( AnotherEntity .class );
39
39
Metadata metadata = ms .buildMetadata ();
40
40
final SessionFactoryBuilder sfb = metadata .getSessionFactoryBuilder ();
41
41
try ( SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor ) sfb .build ()) {
42
- CacheKeyImplementation anEntityCacheKey = createCacheKeyImplementation (
42
+ Object anEntityCacheKey = createCacheKeyImplementation (
43
43
1 ,
44
44
sessionFactory .getRuntimeMetamodels ()
45
45
.getMappingMetamodel ()
46
46
.getEntityDescriptor ( AnEntity .class ),
47
- sessionFactory
47
+ sessionFactory ,
48
+ "tenant"
48
49
);
49
- CacheKeyImplementation anotherEntityCacheKey = createCacheKeyImplementation (
50
+ Object anotherEntityCacheKey = createCacheKeyImplementation (
50
51
1 ,
51
52
sessionFactory .getRuntimeMetamodels ()
52
53
.getMappingMetamodel ()
53
54
.getEntityDescriptor ( AnotherEntity .class ),
54
- sessionFactory
55
+ sessionFactory ,
56
+ "tenant"
55
57
);
56
58
assertFalse ( anEntityCacheKey .equals ( anotherEntityCacheKey ) );
57
59
}
58
60
}
59
61
}
60
62
61
- private CacheKeyImplementation createCacheKeyImplementation (
63
+ @ Test
64
+ @ JiraKey ( value = "HHH-19218" )
65
+ public void testMixedHashCode () {
66
+ try (ServiceRegistryImplementor serviceRegistry = ServiceRegistryUtil .serviceRegistry ()) {
67
+ MetadataSources ms = new MetadataSources ( serviceRegistry );
68
+ ms .addAnnotatedClass ( AnEntity .class ).addAnnotatedClass ( AnotherEntity .class );
69
+ Metadata metadata = ms .buildMetadata ();
70
+ final SessionFactoryBuilder sfb = metadata .getSessionFactoryBuilder ();
71
+ try ( SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor ) sfb .build ()) {
72
+ Object anEntityCacheKey = createCacheKeyImplementation (
73
+ 1 ,
74
+ sessionFactory .getRuntimeMetamodels ()
75
+ .getMappingMetamodel ()
76
+ .getEntityDescriptor ( AnEntity .class ),
77
+ sessionFactory ,
78
+ null
79
+ );
80
+ assertTrue ( (anEntityCacheKey .hashCode () >>> 16 ) != 0 );
81
+ assertTrue ( (anEntityCacheKey .hashCode () << 16 ) != 0 );
82
+
83
+ Object anotherEntityCacheKey = createCacheKeyImplementation (
84
+ 1 ,
85
+ sessionFactory .getRuntimeMetamodels ()
86
+ .getMappingMetamodel ()
87
+ .getEntityDescriptor ( AnotherEntity .class ),
88
+ sessionFactory ,
89
+ "0"
90
+ );
91
+ assertTrue ( (anotherEntityCacheKey .hashCode () >>> 16 ) != 0 );
92
+ assertTrue ( (anotherEntityCacheKey .hashCode () << 16 ) != 0 );
93
+ }
94
+ }
95
+ }
96
+
97
+ private Object createCacheKeyImplementation (
62
98
int id ,
63
99
EntityPersister persister ,
64
- SessionFactoryImplementor sfi ) {
65
- return (CacheKeyImplementation ) DefaultCacheKeysFactory .staticCreateEntityKey ( id , persister , sfi , "tenant" );
100
+ SessionFactoryImplementor sfi ,
101
+ String tenantIdentifier ) {
102
+ return DefaultCacheKeysFactory .staticCreateEntityKey ( id , persister , sfi , tenantIdentifier );
66
103
}
67
104
68
105
@ Entity (name = "AnEntity" )
0 commit comments