5
5
package org .hibernate .orm .test .mapping .converted .converter ;
6
6
7
7
import java .net .MalformedURLException ;
8
- import java .util . Date ;
8
+ import java .time . LocalDate ;
9
9
import jakarta .persistence .AttributeConverter ;
10
10
import jakarta .persistence .Convert ;
11
11
import jakarta .persistence .Entity ;
21
21
import org .hibernate .testing .junit4 .BaseNonConfigCoreFunctionalTestCase ;
22
22
import org .junit .Test ;
23
23
24
- import org .joda .time .LocalDate ;
25
24
26
25
import static org .hibernate .testing .junit4 .ExtraAssertions .assertTyping ;
27
26
import static org .junit .Assert .assertTrue ;
30
29
* @author Steve Ebersole
31
30
*/
32
31
@ JiraKey ( value = "HHH-8842" )
33
- public class BasicJodaTimeConversionTest extends BaseNonConfigCoreFunctionalTestCase {
32
+ public class BasicCustomTimeConversionTest extends BaseNonConfigCoreFunctionalTestCase {
34
33
static boolean convertToDatabaseColumnCalled = false ;
35
34
static boolean convertToEntityAttributeCalled = false ;
36
35
@@ -39,29 +38,31 @@ private void resetFlags() {
39
38
convertToEntityAttributeCalled = false ;
40
39
}
41
40
42
- public static class JodaLocalDateConverter implements AttributeConverter <LocalDate , Date > {
43
- public Date convertToDatabaseColumn (LocalDate localDate ) {
41
+ public record CustomLocalDate (int year ,int month ,int day ) { }
42
+
43
+ public static class CustomLocalDateConverter implements AttributeConverter <CustomLocalDate , LocalDate > {
44
+ public LocalDate convertToDatabaseColumn (CustomLocalDate customLocalDate ) {
44
45
convertToDatabaseColumnCalled = true ;
45
- return localDate . toDate ( );
46
+ return LocalDate . of ( customLocalDate . year (), customLocalDate . month (), customLocalDate . day () );
46
47
}
47
48
48
- public LocalDate convertToEntityAttribute (Date date ) {
49
+ public CustomLocalDate convertToEntityAttribute (LocalDate date ) {
49
50
convertToEntityAttributeCalled = true ;
50
- return LocalDate . fromDateFields ( date );
51
+ return new CustomLocalDate ( date . getYear (), date . getMonthValue (), date . getDayOfMonth () );
51
52
}
52
53
}
53
54
54
55
@ Entity ( name = "TheEntity" )
55
56
public static class TheEntity {
56
57
@ Id
57
58
public Integer id ;
58
- @ Convert ( converter = JodaLocalDateConverter .class )
59
- public LocalDate theDate ;
59
+ @ Convert ( converter = CustomLocalDateConverter .class )
60
+ public CustomLocalDate theDate ;
60
61
61
62
public TheEntity () {
62
63
}
63
64
64
- public TheEntity (Integer id , LocalDate theDate ) {
65
+ public TheEntity (Integer id , CustomLocalDate theDate ) {
65
66
this .id = id ;
66
67
this .theDate = theDate ;
67
68
}
@@ -78,13 +79,13 @@ public void testSimpleConvertUsage() throws MalformedURLException {
78
79
final Type theDatePropertyType = ep .getPropertyType ( "theDate" );
79
80
final ConvertedBasicTypeImpl type = assertTyping ( ConvertedBasicTypeImpl .class , theDatePropertyType );
80
81
final JpaAttributeConverter converter = (JpaAttributeConverter ) type .getValueConverter ();
81
- assertTrue ( JodaLocalDateConverter .class .isAssignableFrom ( converter .getConverterJavaType ().getJavaTypeClass () ) );
82
+ assertTrue ( CustomLocalDateConverter .class .isAssignableFrom ( converter .getConverterJavaType ().getJavaTypeClass () ) );
82
83
83
84
resetFlags ();
84
85
85
86
Session session = openSession ();
86
87
session .getTransaction ().begin ();
87
- session .persist ( new TheEntity ( 1 , new LocalDate ( ) ) );
88
+ session .persist ( new TheEntity ( 1 , new CustomLocalDate ( 2025 , 9 , 26 ) ) );
88
89
session .getTransaction ().commit ();
89
90
session .close ();
90
91
0 commit comments