Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion hibernate-core/hibernate-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ dependencies {
// for test runtime
transitive = true
}
testImplementation "joda-time:joda-time:2.3"
testImplementation jdbcLibs.h2
testImplementation libs.hibernateModelsJandex

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package org.hibernate.orm.test.mapping.converted.converter;

import java.net.MalformedURLException;
import java.util.Date;
import java.time.LocalDate;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
Expand All @@ -21,7 +21,6 @@
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;

import org.joda.time.LocalDate;

import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertTrue;
Expand All @@ -30,7 +29,7 @@
* @author Steve Ebersole
*/
@JiraKey( value = "HHH-8842" )
public class BasicJodaTimeConversionTest extends BaseNonConfigCoreFunctionalTestCase {
public class BasicCustomTimeConversionTest extends BaseNonConfigCoreFunctionalTestCase {
static boolean convertToDatabaseColumnCalled = false;
static boolean convertToEntityAttributeCalled = false;

Expand All @@ -39,29 +38,31 @@ private void resetFlags() {
convertToEntityAttributeCalled = false;
}

public static class JodaLocalDateConverter implements AttributeConverter<LocalDate, Date> {
public Date convertToDatabaseColumn(LocalDate localDate) {
public record CustomLocalDate(int year,int month,int day) { }

public static class CustomLocalDateConverter implements AttributeConverter<CustomLocalDate, LocalDate> {
public LocalDate convertToDatabaseColumn(CustomLocalDate customLocalDate) {
convertToDatabaseColumnCalled = true;
return localDate.toDate();
return LocalDate.of(customLocalDate.year(),customLocalDate.month(), customLocalDate.day() );
}

public LocalDate convertToEntityAttribute(Date date) {
public CustomLocalDate convertToEntityAttribute(LocalDate date) {
convertToEntityAttributeCalled = true;
return LocalDate.fromDateFields( date );
return new CustomLocalDate( date.getYear(), date.getMonthValue(), date.getDayOfMonth());
}
}

@Entity( name = "TheEntity" )
public static class TheEntity {
@Id
public Integer id;
@Convert( converter = JodaLocalDateConverter.class )
public LocalDate theDate;
@Convert( converter = CustomLocalDateConverter.class )
public CustomLocalDate theDate;

public TheEntity() {
}

public TheEntity(Integer id, LocalDate theDate) {
public TheEntity(Integer id, CustomLocalDate theDate) {
this.id = id;
this.theDate = theDate;
}
Expand All @@ -78,13 +79,13 @@ public void testSimpleConvertUsage() throws MalformedURLException {
final Type theDatePropertyType = ep.getPropertyType( "theDate" );
final ConvertedBasicTypeImpl type = assertTyping( ConvertedBasicTypeImpl.class, theDatePropertyType );
final JpaAttributeConverter converter = (JpaAttributeConverter) type.getValueConverter();
assertTrue( JodaLocalDateConverter.class.isAssignableFrom( converter.getConverterJavaType().getJavaTypeClass() ) );
assertTrue( CustomLocalDateConverter.class.isAssignableFrom( converter.getConverterJavaType().getJavaTypeClass() ) );

resetFlags();

Session session = openSession();
session.getTransaction().begin();
session.persist( new TheEntity( 1, new LocalDate() ) );
session.persist( new TheEntity( 1, new CustomLocalDate( 2025, 9, 26 ) ) );
session.getTransaction().commit();
session.close();

Expand Down