4
4
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5
5
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6
6
*/
7
- package org .hibernate .orm .test .mapping .converted .converter .elementCollection . embeddable ;
7
+ package org .hibernate .orm .test .mapping .converted .converter .elementCollection ;
8
8
9
9
import java .math .BigDecimal ;
10
10
import java .util .ArrayList ;
15
15
import org .hibernate .testing .orm .junit .DomainModel ;
16
16
import org .hibernate .testing .orm .junit .SessionFactory ;
17
17
import org .hibernate .testing .orm .junit .SessionFactoryScope ;
18
+ import org .junit .jupiter .api .AfterEach ;
19
+ import org .junit .jupiter .api .BeforeEach ;
18
20
import org .junit .jupiter .api .Test ;
19
21
20
22
import jakarta .persistence .AttributeConverter ;
23
25
import jakarta .persistence .Embeddable ;
24
26
import jakarta .persistence .Entity ;
25
27
import jakarta .persistence .FetchType ;
26
- import jakarta .persistence .GeneratedValue ;
27
28
import jakarta .persistence .Id ;
28
29
29
30
/**
32
33
*/
33
34
34
35
@ DomainModel (annotatedClasses = {
35
- EmbeddableTests .ProductEntity .class ,
36
- EmbeddableTests .MyBigDecimalConverter .class
36
+ CollectionEmbeddableElementConversionTest .ProductEntity .class ,
37
+ CollectionEmbeddableElementConversionTest .MyBigDecimalConverter .class
37
38
})
38
39
@ SessionFactory
39
40
@ TestForIssue (jiraKey = "HHH-15211" )
40
- class EmbeddableTests {
41
+ class CollectionEmbeddableElementConversionTest {
41
42
42
- @ Test
43
- void testNoClassCastExceptionThrown (SessionFactoryScope scope ) {
44
- final ProductEntity entity = new ProductEntity ();
43
+ @ BeforeEach
44
+ void setUp (SessionFactoryScope scope ) {
45
+ final ProductEntity entity = new ProductEntity ( 1 );
45
46
entity .prices = Collections .singletonList ( new ProductPrice ( new MyBigDecimal ( 100.0 ) ) );
46
- final Integer productId = scope .fromTransaction ( session -> {
47
+ scope .fromTransaction ( session -> {
47
48
session .persist ( entity );
48
49
return entity .productId ;
49
50
} );
51
+ }
50
52
51
- // without fixing, the following statement would thrown "ClassCastException"
53
+ @ Test
54
+ void testNoClassCastExceptionThrown (SessionFactoryScope scope ) {
52
55
scope .inTransaction ( session -> session .get (
53
56
ProductEntity .class ,
54
- productId
57
+ 1
55
58
) );
56
59
}
57
60
61
+ @ AfterEach
62
+ void tearDown (SessionFactoryScope scope ) {
63
+ scope .inTransaction (
64
+ (session ) -> session .createQuery ( "delete ProductEntity" ).executeUpdate ()
65
+ );
66
+ }
67
+
58
68
@ Entity (name = "ProductEntity" )
59
69
static class ProductEntity {
60
70
@ Id
61
- @ GeneratedValue
62
71
Integer productId ;
63
72
73
+ ProductEntity () {
74
+ }
75
+
76
+ ProductEntity (Integer productId ) {
77
+ this .productId = productId ;
78
+ }
79
+
64
80
@ ElementCollection (fetch = FetchType .EAGER )
65
81
List <ProductPrice > prices = new ArrayList <>();
66
82
}
@@ -69,7 +85,9 @@ static class ProductEntity {
69
85
static class ProductPrice {
70
86
MyBigDecimal price ;
71
87
72
- ProductPrice () {}
88
+ ProductPrice () {
89
+ }
90
+
73
91
ProductPrice (MyBigDecimal price ) {
74
92
this .price = price ;
75
93
}
@@ -95,9 +113,6 @@ public MyBigDecimal convertToEntityAttribute(BigDecimal dbData) {
95
113
return new MyBigDecimal ( dbData .doubleValue () );
96
114
}
97
115
98
- public MyBigDecimalConverter () {
99
- System .out .println ( "Registered MyBigDecimalConverter" );
100
- }
101
116
}
102
117
103
118
}
0 commit comments