55package org .hibernate .orm .test .mapping .converted .converter ;
66
77import java .net .MalformedURLException ;
8- import java .util . Date ;
8+ import java .time . LocalDate ;
99import jakarta .persistence .AttributeConverter ;
1010import jakarta .persistence .Convert ;
1111import jakarta .persistence .Entity ;
2121import org .hibernate .testing .junit4 .BaseNonConfigCoreFunctionalTestCase ;
2222import org .junit .Test ;
2323
24- import org .joda .time .LocalDate ;
2524
2625import static org .hibernate .testing .junit4 .ExtraAssertions .assertTyping ;
2726import static org .junit .Assert .assertTrue ;
3029 * @author Steve Ebersole
3130 */
3231@ JiraKey ( value = "HHH-8842" )
33- public class BasicJodaTimeConversionTest extends BaseNonConfigCoreFunctionalTestCase {
32+ public class BasicCustomTimeConversionTest extends BaseNonConfigCoreFunctionalTestCase {
3433 static boolean convertToDatabaseColumnCalled = false ;
3534 static boolean convertToEntityAttributeCalled = false ;
3635
@@ -39,29 +38,31 @@ private void resetFlags() {
3938 convertToEntityAttributeCalled = false ;
4039 }
4140
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 ) {
4445 convertToDatabaseColumnCalled = true ;
45- return localDate . toDate ( );
46+ return LocalDate . of ( customLocalDate . year (), customLocalDate . month (), customLocalDate . day () );
4647 }
4748
48- public LocalDate convertToEntityAttribute (Date date ) {
49+ public CustomLocalDate convertToEntityAttribute (LocalDate date ) {
4950 convertToEntityAttributeCalled = true ;
50- return LocalDate . fromDateFields ( date );
51+ return new CustomLocalDate ( date . getYear (), date . getMonthValue (), date . getDayOfMonth () );
5152 }
5253 }
5354
5455 @ Entity ( name = "TheEntity" )
5556 public static class TheEntity {
5657 @ Id
5758 public Integer id ;
58- @ Convert ( converter = JodaLocalDateConverter .class )
59- public LocalDate theDate ;
59+ @ Convert ( converter = CustomLocalDateConverter .class )
60+ public CustomLocalDate theDate ;
6061
6162 public TheEntity () {
6263 }
6364
64- public TheEntity (Integer id , LocalDate theDate ) {
65+ public TheEntity (Integer id , CustomLocalDate theDate ) {
6566 this .id = id ;
6667 this .theDate = theDate ;
6768 }
@@ -78,13 +79,13 @@ public void testSimpleConvertUsage() throws MalformedURLException {
7879 final Type theDatePropertyType = ep .getPropertyType ( "theDate" );
7980 final ConvertedBasicTypeImpl type = assertTyping ( ConvertedBasicTypeImpl .class , theDatePropertyType );
8081 final JpaAttributeConverter converter = (JpaAttributeConverter ) type .getValueConverter ();
81- assertTrue ( JodaLocalDateConverter .class .isAssignableFrom ( converter .getConverterJavaType ().getJavaTypeClass () ) );
82+ assertTrue ( CustomLocalDateConverter .class .isAssignableFrom ( converter .getConverterJavaType ().getJavaTypeClass () ) );
8283
8384 resetFlags ();
8485
8586 Session session = openSession ();
8687 session .getTransaction ().begin ();
87- session .persist ( new TheEntity ( 1 , new LocalDate ( ) ) );
88+ session .persist ( new TheEntity ( 1 , new CustomLocalDate ( 2025 , 9 , 26 ) ) );
8889 session .getTransaction ().commit ();
8990 session .close ();
9091
0 commit comments