7
7
package org .hibernate .orm .test .type .contributor .usertype ;
8
8
9
9
import java .io .Serializable ;
10
+ import java .math .BigDecimal ;
11
+ import java .util .Currency ;
10
12
13
+ import org .hibernate .boot .model .TypeContributor ;
14
+ import org .hibernate .orm .test .mapping .basic .MonetaryAmount ;
11
15
import org .hibernate .type .CustomType ;
12
16
import org .hibernate .type .Type ;
13
17
import org .hibernate .type .UserComponentType ;
14
18
19
+ import org .hibernate .testing .orm .junit .BootstrapServiceRegistry ;
15
20
import org .hibernate .testing .orm .junit .DomainModel ;
21
+ import org .hibernate .testing .orm .junit .Jira ;
16
22
import org .hibernate .testing .orm .junit .JiraKey ;
17
23
import org .hibernate .testing .orm .junit .SessionFactory ;
18
24
import org .hibernate .testing .orm .junit .SessionFactoryScope ;
29
35
annotatedClasses = {
30
36
ContributedUserTypeTest .StringWrapperTestEntity .class ,
31
37
ContributedUserTypeTest .MyCompositeValueTestEntity .class ,
38
+ ContributedUserTypeTest .Wallet .class
32
39
},
33
40
typeContributors = { StringWrapperTypeContributor .class , MyCompositeValueTypeContributor .class }
34
41
)
35
42
@ SessionFactory
43
+ @ BootstrapServiceRegistry (
44
+ javaServices = {
45
+ @ BootstrapServiceRegistry .JavaService ( role = TypeContributor .class , impl = ServiceLoadedCustomUserTypeTypeContributor .class )
46
+ }
47
+ )
36
48
public class ContributedUserTypeTest {
49
+
50
+ public void tearDown (SessionFactoryScope scope ) {
51
+ scope .inTransaction (
52
+ session -> {
53
+ session .createMutationQuery ( "delete from Wallet" ).executeUpdate ();
54
+ }
55
+ );
56
+ }
57
+
37
58
@ Test
38
59
@ JiraKey ( "HHH-14408" )
39
60
public void test (SessionFactoryScope scope ) {
@@ -81,6 +102,28 @@ public void testCompositeParameter(SessionFactoryScope scope) {
81
102
);
82
103
}
83
104
105
+ @ Test
106
+ @ Jira ( value = "https://hibernate.atlassian.net/browse/HHH-17635" )
107
+ public void testServiceLoadedCustomUserType (SessionFactoryScope scope ) {
108
+ scope .inTransaction (
109
+ session -> {
110
+ Wallet wallet = new Wallet ();
111
+ wallet .setId ( 1L );
112
+ wallet .setMoney ( new MonetaryAmount ( new BigDecimal ( 1000 ), Currency .getInstance ("EUR" )) );
113
+ session .persist ( wallet );
114
+ }
115
+ );
116
+ scope .inTransaction (
117
+ session -> {
118
+ Wallet w = session .createSelectionQuery ( "from Wallet" , Wallet .class ).getSingleResult ();
119
+ MonetaryAmount amount = w .getMoney ();
120
+ Assertions .assertNotNull ( amount );
121
+ Assertions .assertEquals ( 1000 , amount .getAmount ().intValue () );
122
+ Assertions .assertEquals ( "EUR" , amount .getCurrency ().getCurrencyCode () );
123
+ }
124
+ );
125
+ }
126
+
84
127
@ Entity ( name = "StringWrapperTestEntity" )
85
128
public static class StringWrapperTestEntity implements Serializable {
86
129
@ Id
@@ -94,4 +137,30 @@ public static class MyCompositeValueTestEntity implements Serializable {
94
137
private Integer id ;
95
138
private MyCompositeValue compositeValue ;
96
139
}
140
+
141
+ @ Entity (name = "Wallet" )
142
+ public static class Wallet {
143
+
144
+ @ Id
145
+ private Long id ;
146
+
147
+ private MonetaryAmount money ;
148
+
149
+ public Long getId () {
150
+ return id ;
151
+ }
152
+
153
+ public void setId (Long id ) {
154
+ this .id = id ;
155
+ }
156
+
157
+ public MonetaryAmount getMoney () {
158
+ return money ;
159
+ }
160
+
161
+ public void setMoney (MonetaryAmount money ) {
162
+ this .money = money ;
163
+ }
164
+ }
165
+
97
166
}
0 commit comments