Fix JPA 3.2 deprecations

This commit is contained in:
Artem Bilan
2025-06-09 16:22:52 -04:00
parent b07d04f9e5
commit 260073d18a
5 changed files with 34 additions and 53 deletions

View File

@@ -17,7 +17,6 @@
package org.springframework.integration.jpa.core;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
@@ -148,14 +147,11 @@ public class HibernateJpaOperationsTests {
StudentDomain retrievedStudent = (StudentDomain) students.iterator().next();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
assertThat(retrievedStudent.getDateOfBirth()).isEqualTo(formatter.parse("1980/01/01"));
assertThat(retrievedStudent.getDateOfBirth()).isEqualTo(LocalDate.of(1980, 1, 1));
assertThat(retrievedStudent.getFirstName()).isEqualTo("First One");
assertThat(retrievedStudent.getGender()).isEqualTo(Gender.MALE);
assertThat(retrievedStudent.getLastName()).isEqualTo("Last One");
assertThat(retrievedStudent.getLastUpdated()).isNotNull();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 the original author or authors.
* Copyright 2016-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
package org.springframework.integration.jpa.dsl;
import java.util.Calendar;
import java.util.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import jakarta.persistence.EntityManagerFactory;
@@ -122,15 +122,12 @@ public class JpaTests {
assertThat(results1).isNotNull();
assertThat(results1.size() == 3).isTrue();
Calendar dateOfBirth = Calendar.getInstance();
dateOfBirth.set(1981, 9, 27);
StudentDomain student = new StudentDomain()
.withFirstName("Artem")
.withLastName("Bilan")
.withGender(Gender.MALE)
.withDateOfBirth(dateOfBirth.getTime())
.withLastUpdated(new Date());
.withDateOfBirth(LocalDate.of(1981, 10, 27))
.withLastUpdated(LocalDateTime.now());
assertThat(student.getRollNumber()).isNull();
@@ -145,15 +142,12 @@ public class JpaTests {
@Test
public void testUpdatingGatewayFlow() {
Calendar dateOfBirth = Calendar.getInstance();
dateOfBirth.set(1981, 9, 27);
StudentDomain student = new StudentDomain()
.withFirstName("Artem")
.withLastName("Bilan")
.withGender(Gender.MALE)
.withDateOfBirth(dateOfBirth.getTime())
.withLastUpdated(new Date());
.withDateOfBirth(LocalDate.of(1981, 10, 27))
.withLastUpdated(LocalDateTime.now());
assertThat(student.getRollNumber()).isNull();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
package org.springframework.integration.jpa.test;
import java.util.Calendar;
import java.util.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean;
@@ -32,6 +32,7 @@ import org.springframework.messaging.MessageChannel;
*
* @author Gunnar Hillert
* @author Gary Russell
* @author Artem Bilan
* @since 2.2
*
*/
@@ -43,24 +44,19 @@ public final class JpaTestUtils {
public static StudentDomain getTestStudent() {
Calendar dateOfBirth = Calendar.getInstance();
dateOfBirth.set(1984, 0, 31);
StudentDomain student = new StudentDomain()
return new StudentDomain()
.withFirstName("First Executor")
.withLastName("Last Executor")
.withGender(Gender.MALE)
.withDateOfBirth(dateOfBirth.getTime())
.withLastUpdated(new Date());
return student;
.withDateOfBirth(LocalDate.of(1984, 1, 31))
.withLastUpdated(LocalDateTime.now());
}
public static SourcePollingChannelAdapter getSourcePollingChannelAdapter(MessageSource<?> adapter,
MessageChannel channel,
PollerMetadata poller,
GenericApplicationContext context,
ClassLoader beanClassLoader) throws Exception {
ClassLoader beanClassLoader) {
SourcePollingChannelAdapterFactoryBean fb = new SourcePollingChannelAdapterFactoryBean();
fb.setSource(adapter);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,8 @@
package org.springframework.integration.jpa.test.entity;
import java.util.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
@@ -27,8 +28,6 @@ import jakarta.persistence.NamedQueries;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
/**
* The JPA Entity for the Student class
@@ -47,7 +46,8 @@ import jakarta.persistence.TemporalType;
@NamedQuery(name = "selectStudent", query = "select s from Student s where s.lastName = 'Last One'"),
@NamedQuery(name = "updateStudent", query = "update Student s set s.lastName = :lastName, s.lastUpdated = :lastUpdated where s.rollNumber in (select max(a.rollNumber) from Student a)")
})
@NamedNativeQuery(resultClass = StudentDomain.class, name = "updateStudentNativeQuery", query = "update Student s set s.lastName = :lastName, lastUpdated = :lastUpdated where s.rollNumber in (select max(a.rollNumber) from Student a)")
@NamedNativeQuery(resultClass = StudentDomain.class, name = "updateStudentNativeQuery",
query = "update Student s set s.lastName = :lastName, lastUpdated = :lastUpdated where s.rollNumber in (select max(a.rollNumber) from Student a)")
@SequenceGenerator(name = "student_sequence", initialValue = 1004, allocationSize = 1)
public class StudentDomain {
@@ -66,12 +66,10 @@ public class StudentDomain {
private String gender;
@Column(name = "dateOfBirth")
@Temporal(TemporalType.DATE)
private Date dateOfBirth;
private LocalDate dateOfBirth;
@Column(name = "lastUpdated")
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdated;
private LocalDateTime lastUpdated;
public Long getRollNumber() {
return rollNumber;
@@ -105,19 +103,19 @@ public class StudentDomain {
this.gender = gender.getIdentifier();
}
public Date getDateOfBirth() {
public LocalDate getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
public void setDateOfBirth(LocalDate dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public Date getLastUpdated() {
public LocalDateTime getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(Date lastUpdated) {
public void setLastUpdated(LocalDateTime lastUpdated) {
this.lastUpdated = lastUpdated;
}
@@ -143,12 +141,12 @@ public class StudentDomain {
return this;
}
public StudentDomain withDateOfBirth(Date dateOfBirth) {
public StudentDomain withDateOfBirth(LocalDate dateOfBirth) {
setDateOfBirth(dateOfBirth);
return this;
}
public StudentDomain withLastUpdated(Date lastUpdated) {
public StudentDomain withLastUpdated(LocalDateTime lastUpdated) {
setLastUpdated(lastUpdated);
return this;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,14 +16,12 @@
package org.springframework.integration.jpa.test.entity;
import java.util.Date;
import java.time.LocalDateTime;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
/**
* The Entity for Student read status
@@ -40,8 +38,7 @@ public class StudentReadStatus {
private int rollNumber;
@Column(name = "readAt")
@Temporal(TemporalType.TIMESTAMP)
private Date readAt;
private LocalDateTime readAt;
public int getRollNumber() {
return rollNumber;
@@ -51,11 +48,11 @@ public class StudentReadStatus {
this.rollNumber = rollNumber;
}
public Date getReadAt() {
public LocalDateTime getReadAt() {
return readAt;
}
public void setReadAt(Date readAt) {
public void setReadAt(LocalDateTime readAt) {
this.readAt = readAt;
}