Skip to content

Commit 260073d

Browse files
committed
Fix JPA 3.2 deprecations
1 parent b07d04f commit 260073d

File tree

5 files changed

+34
-53
lines changed

5 files changed

+34
-53
lines changed

spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/HibernateJpaOperationsTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.integration.jpa.core;
1818

1919
import java.text.ParseException;
20-
import java.text.SimpleDateFormat;
2120
import java.time.LocalDate;
2221
import java.util.ArrayList;
2322
import java.util.List;
@@ -148,14 +147,11 @@ public void testExecuteSelectWithNativeQueryReturningEntityClass() throws ParseE
148147

149148
StudentDomain retrievedStudent = (StudentDomain) students.iterator().next();
150149

151-
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
152-
153-
assertThat(retrievedStudent.getDateOfBirth()).isEqualTo(formatter.parse("1980/01/01"));
150+
assertThat(retrievedStudent.getDateOfBirth()).isEqualTo(LocalDate.of(1980, 1, 1));
154151
assertThat(retrievedStudent.getFirstName()).isEqualTo("First One");
155152
assertThat(retrievedStudent.getGender()).isEqualTo(Gender.MALE);
156153
assertThat(retrievedStudent.getLastName()).isEqualTo("Last One");
157154
assertThat(retrievedStudent.getLastUpdated()).isNotNull();
158-
159155
}
160156

161157
@Test

spring-integration-jpa/src/test/java/org/springframework/integration/jpa/dsl/JpaTests.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 the original author or authors.
2+
* Copyright 2016-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.integration.jpa.dsl;
1818

19-
import java.util.Calendar;
20-
import java.util.Date;
19+
import java.time.LocalDate;
20+
import java.time.LocalDateTime;
2121
import java.util.List;
2222

2323
import jakarta.persistence.EntityManagerFactory;
@@ -122,15 +122,12 @@ public void testOutboundAdapterFlow() {
122122
assertThat(results1).isNotNull();
123123
assertThat(results1.size() == 3).isTrue();
124124

125-
Calendar dateOfBirth = Calendar.getInstance();
126-
dateOfBirth.set(1981, 9, 27);
127-
128125
StudentDomain student = new StudentDomain()
129126
.withFirstName("Artem")
130127
.withLastName("Bilan")
131128
.withGender(Gender.MALE)
132-
.withDateOfBirth(dateOfBirth.getTime())
133-
.withLastUpdated(new Date());
129+
.withDateOfBirth(LocalDate.of(1981, 10, 27))
130+
.withLastUpdated(LocalDateTime.now());
134131

135132
assertThat(student.getRollNumber()).isNull();
136133

@@ -145,15 +142,12 @@ public void testOutboundAdapterFlow() {
145142

146143
@Test
147144
public void testUpdatingGatewayFlow() {
148-
Calendar dateOfBirth = Calendar.getInstance();
149-
dateOfBirth.set(1981, 9, 27);
150-
151145
StudentDomain student = new StudentDomain()
152146
.withFirstName("Artem")
153147
.withLastName("Bilan")
154148
.withGender(Gender.MALE)
155-
.withDateOfBirth(dateOfBirth.getTime())
156-
.withLastUpdated(new Date());
149+
.withDateOfBirth(LocalDate.of(1981, 10, 27))
150+
.withLastUpdated(LocalDateTime.now());
157151

158152
assertThat(student.getRollNumber()).isNull();
159153

spring-integration-jpa/src/test/java/org/springframework/integration/jpa/test/JpaTestUtils.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.integration.jpa.test;
1818

19-
import java.util.Calendar;
20-
import java.util.Date;
19+
import java.time.LocalDate;
20+
import java.time.LocalDateTime;
2121

2222
import org.springframework.context.support.GenericApplicationContext;
2323
import org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean;
@@ -32,6 +32,7 @@
3232
*
3333
* @author Gunnar Hillert
3434
* @author Gary Russell
35+
* @author Artem Bilan
3536
* @since 2.2
3637
*
3738
*/
@@ -43,24 +44,19 @@ private JpaTestUtils() {
4344

4445
public static StudentDomain getTestStudent() {
4546

46-
Calendar dateOfBirth = Calendar.getInstance();
47-
dateOfBirth.set(1984, 0, 31);
48-
49-
StudentDomain student = new StudentDomain()
47+
return new StudentDomain()
5048
.withFirstName("First Executor")
5149
.withLastName("Last Executor")
5250
.withGender(Gender.MALE)
53-
.withDateOfBirth(dateOfBirth.getTime())
54-
.withLastUpdated(new Date());
55-
56-
return student;
51+
.withDateOfBirth(LocalDate.of(1984, 1, 31))
52+
.withLastUpdated(LocalDateTime.now());
5753
}
5854

5955
public static SourcePollingChannelAdapter getSourcePollingChannelAdapter(MessageSource<?> adapter,
6056
MessageChannel channel,
6157
PollerMetadata poller,
6258
GenericApplicationContext context,
63-
ClassLoader beanClassLoader) throws Exception {
59+
ClassLoader beanClassLoader) {
6460

6561
SourcePollingChannelAdapterFactoryBean fb = new SourcePollingChannelAdapterFactoryBean();
6662
fb.setSource(adapter);

spring-integration-jpa/src/test/java/org/springframework/integration/jpa/test/entity/StudentDomain.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,8 @@
1616

1717
package org.springframework.integration.jpa.test.entity;
1818

19-
import java.util.Date;
19+
import java.time.LocalDate;
20+
import java.time.LocalDateTime;
2021

2122
import jakarta.persistence.Column;
2223
import jakarta.persistence.Entity;
@@ -27,8 +28,6 @@
2728
import jakarta.persistence.NamedQuery;
2829
import jakarta.persistence.SequenceGenerator;
2930
import jakarta.persistence.Table;
30-
import jakarta.persistence.Temporal;
31-
import jakarta.persistence.TemporalType;
3231

3332
/**
3433
* The JPA Entity for the Student class
@@ -47,7 +46,8 @@
4746
@NamedQuery(name = "selectStudent", query = "select s from Student s where s.lastName = 'Last One'"),
4847
@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)")
4948
})
50-
@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)")
49+
@NamedNativeQuery(resultClass = StudentDomain.class, name = "updateStudentNativeQuery",
50+
query = "update Student s set s.lastName = :lastName, lastUpdated = :lastUpdated where s.rollNumber in (select max(a.rollNumber) from Student a)")
5151
@SequenceGenerator(name = "student_sequence", initialValue = 1004, allocationSize = 1)
5252
public class StudentDomain {
5353

@@ -66,12 +66,10 @@ public class StudentDomain {
6666
private String gender;
6767

6868
@Column(name = "dateOfBirth")
69-
@Temporal(TemporalType.DATE)
70-
private Date dateOfBirth;
69+
private LocalDate dateOfBirth;
7170

7271
@Column(name = "lastUpdated")
73-
@Temporal(TemporalType.TIMESTAMP)
74-
private Date lastUpdated;
72+
private LocalDateTime lastUpdated;
7573

7674
public Long getRollNumber() {
7775
return rollNumber;
@@ -105,19 +103,19 @@ public void setGender(Gender gender) {
105103
this.gender = gender.getIdentifier();
106104
}
107105

108-
public Date getDateOfBirth() {
106+
public LocalDate getDateOfBirth() {
109107
return dateOfBirth;
110108
}
111109

112-
public void setDateOfBirth(Date dateOfBirth) {
110+
public void setDateOfBirth(LocalDate dateOfBirth) {
113111
this.dateOfBirth = dateOfBirth;
114112
}
115113

116-
public Date getLastUpdated() {
114+
public LocalDateTime getLastUpdated() {
117115
return lastUpdated;
118116
}
119117

120-
public void setLastUpdated(Date lastUpdated) {
118+
public void setLastUpdated(LocalDateTime lastUpdated) {
121119
this.lastUpdated = lastUpdated;
122120
}
123121

@@ -143,12 +141,12 @@ public StudentDomain withGender(Gender gender) {
143141
return this;
144142
}
145143

146-
public StudentDomain withDateOfBirth(Date dateOfBirth) {
144+
public StudentDomain withDateOfBirth(LocalDate dateOfBirth) {
147145
setDateOfBirth(dateOfBirth);
148146
return this;
149147
}
150148

151-
public StudentDomain withLastUpdated(Date lastUpdated) {
149+
public StudentDomain withLastUpdated(LocalDateTime lastUpdated) {
152150
setLastUpdated(lastUpdated);
153151
return this;
154152
}

spring-integration-jpa/src/test/java/org/springframework/integration/jpa/test/entity/StudentReadStatus.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,14 +16,12 @@
1616

1717
package org.springframework.integration.jpa.test.entity;
1818

19-
import java.util.Date;
19+
import java.time.LocalDateTime;
2020

2121
import jakarta.persistence.Column;
2222
import jakarta.persistence.Entity;
2323
import jakarta.persistence.Id;
2424
import jakarta.persistence.Table;
25-
import jakarta.persistence.Temporal;
26-
import jakarta.persistence.TemporalType;
2725

2826
/**
2927
* The Entity for Student read status
@@ -40,8 +38,7 @@ public class StudentReadStatus {
4038
private int rollNumber;
4139

4240
@Column(name = "readAt")
43-
@Temporal(TemporalType.TIMESTAMP)
44-
private Date readAt;
41+
private LocalDateTime readAt;
4542

4643
public int getRollNumber() {
4744
return rollNumber;
@@ -51,11 +48,11 @@ public void setRollNumber(int rollNumber) {
5148
this.rollNumber = rollNumber;
5249
}
5350

54-
public Date getReadAt() {
51+
public LocalDateTime getReadAt() {
5552
return readAt;
5653
}
5754

58-
public void setReadAt(Date readAt) {
55+
public void setReadAt(LocalDateTime readAt) {
5956
this.readAt = readAt;
6057
}
6158

0 commit comments

Comments
 (0)