Skip to content

Commit b074f19

Browse files
committed
Upgrade to Hibernate 6.1.x; fix JPA tests
1 parent 5ded860 commit b074f19

File tree

7 files changed

+26
-60
lines changed

7 files changed

+26
-60
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ext {
6565
groovyVersion = '3.0.10'
6666
hamcrestVersion = '2.2'
6767
hazelcastVersion = '5.1.1'
68-
hibernateVersion = '5.6.8.Final'
68+
hibernateVersion = '6.1.1.Final'
6969
hsqldbVersion = '2.6.1'
7070
h2Version = '2.1.212'
7171
jacksonVersion = '2.13.3'
@@ -759,7 +759,7 @@ project('spring-integration-jpa') {
759759
exclude group: 'org.springframework'
760760
}
761761
testImplementation "com.h2database:h2:$h2Version"
762-
testImplementation "org.hibernate:hibernate-core-jakarta:$hibernateVersion"
762+
testImplementation "org.hibernate.orm:hibernate-core:$hibernateVersion"
763763
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
764764
}
765765
}

spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -110,9 +110,9 @@ protected ExpressionEvaluatingParameterSource(Object input, List<JpaParameter> p
110110
@Override
111111
@Nullable
112112
public Object getValueByPosition(int position) {
113-
Assert.isTrue(position >= 0, "The position must be non-negative.");
113+
Assert.isTrue(position > 0, "The position must be non-negative.");
114114
if (position <= this.parameters.size()) {
115-
JpaParameter parameter = this.parameters.get(position);
115+
JpaParameter parameter = this.parameters.get(position - 1);
116116
String parameterName = parameter.getName();
117117
if (parameterName != null) {
118118
return getValue(parameterName);

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

Lines changed: 2 additions & 2 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-2022 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.
@@ -208,7 +208,7 @@ public void testResultStartingFromThirdRecordForJPAQuery() {
208208
@Test
209209
public void testResultStartingFromThirdRecordForNativeQuery() {
210210
final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
211-
jpaExecutor.setNativeQuery("select * from Student s");
211+
jpaExecutor.setJpaQuery("select s from Student s");
212212
jpaExecutor.setFirstResultExpression(new LiteralExpression("2"));
213213
jpaExecutor.setBeanFactory(this.beanFactory);
214214
jpaExecutor.afterPropertiesSet();

spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayIntegrationTests-context.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,4 @@
6363
<int-jpa:transactional/>
6464
</int-jpa:retrieving-outbound-gateway>
6565

66-
<int:channel id="invalidIdType"/>
67-
68-
<int-jpa:retrieving-outbound-gateway
69-
entity-manager="entityManager"
70-
request-channel="invalidIdType"
71-
entity-class="org.springframework.integration.jpa.test.entity.StudentDomain"
72-
id-expression="payload"/>
73-
7466
</beans>

spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayIntegrationTests.java

Lines changed: 4 additions & 29 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-2022 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.
@@ -17,13 +17,12 @@
1717
package org.springframework.integration.jpa.outbound;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20-
import static org.assertj.core.api.Assertions.fail;
20+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2121

2222
import java.util.List;
2323

2424
import jakarta.persistence.EntityManager;
2525

26-
import org.hibernate.TypeMismatchException;
2726
import org.junit.jupiter.api.AfterEach;
2827
import org.junit.jupiter.api.Test;
2928

@@ -34,7 +33,6 @@
3433
import org.springframework.integration.support.MessageBuilder;
3534
import org.springframework.messaging.Message;
3635
import org.springframework.messaging.MessageHandler;
37-
import org.springframework.messaging.MessageHandlingException;
3836
import org.springframework.messaging.PollableChannel;
3937
import org.springframework.messaging.SubscribableChannel;
4038
import org.springframework.test.annotation.DirtiesContext;
@@ -79,10 +77,6 @@ public class JpaOutboundGatewayIntegrationTests {
7977
@Qualifier("findResultChannel")
8078
private PollableChannel findResultChannel;
8179

82-
@Autowired
83-
@Qualifier("invalidIdType")
84-
private SubscribableChannel invalidIdTypeChannel;
85-
8680
@Autowired
8781
private EntityManager entityManager;
8882

@@ -151,28 +145,9 @@ public void testFindAndDelete() {
151145
Message<?> receive = this.findResultChannel.receive(2000);
152146
assertThat(receive).isNotNull();
153147

154-
try {
155-
this.findAndDeleteChannel.send(message);
156-
}
157-
catch (Exception e) {
158-
assertThat(e).isInstanceOf(ReplyRequiredException.class);
159-
}
160-
}
161148

162-
@Test
163-
public void testInvalidIdType() {
164-
Message<Integer> message = MessageBuilder.withPayload(1).build();
165-
try {
166-
this.invalidIdTypeChannel.send(message);
167-
fail("PersistenceException expected");
168-
}
169-
catch (Exception e) {
170-
assertThat(e).isInstanceOf(MessageHandlingException.class);
171-
assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class);
172-
assertThat(e.getCause().getCause()).isInstanceOf(TypeMismatchException.class);
173-
assertThat(e.getCause().getMessage())
174-
.contains("Expected: class java.lang.Long, got class java.lang.Integer");
175-
}
149+
assertThatExceptionOfType(ReplyRequiredException.class)
150+
.isThrownBy(() -> this.findAndDeleteChannel.send(message));
176151
}
177152

178153
}

spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayTests-context.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
<bean class="org.springframework.integration.jpa.core.JpaExecutor">
187187
<constructor-arg name="entityManager" ref="entityManager"/>
188188
<property name="entityClass" value="org.springframework.integration.jpa.test.entity.StudentDomain"/>
189-
<property name="jpaQuery" value="from Student s where s.firstName = ?0 and s.lastName = ?1"/>
189+
<property name="jpaQuery" value="from Student s where s.firstName = ?1 and s.lastName = ?2"/>
190190
<property name="expectSingleResult" value="true"/>
191191
<property name="jpaParameters" >
192192
<util:list>

spring-integration-jpa/src/test/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactoryTests.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -24,14 +24,16 @@
2424
import java.util.Collections;
2525
import java.util.List;
2626

27-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
2828

2929
import org.springframework.beans.factory.BeanFactory;
3030
import org.springframework.integration.jpa.support.JpaParameter;
3131

3232
/**
3333
*
3434
* @author Gunnar Hillert
35+
* @author Artem Bilan
36+
*
3537
* @since 2.2
3638
*
3739
*/
@@ -57,7 +59,6 @@ public void testMapInput() {
5759

5860
@Test
5961
public void testListOfMapsInput() {
60-
@SuppressWarnings("unchecked")
6162
ParameterSource source = factory.createParameterSource(Arrays.asList(Collections.singletonMap("foo", "bar"),
6263
Collections.singletonMap("foo", "bucket")));
6364
String expression = "foo";
@@ -83,8 +84,7 @@ public void testMapInputWithMappedExpression() {
8384

8485
@Test
8586
public void testMapInputWithMappedExpressionResolveStatic() {
86-
87-
List<JpaParameter> parameters = new ArrayList<JpaParameter>();
87+
List<JpaParameter> parameters = new ArrayList<>();
8888
parameters.add(new JpaParameter("spam", null, "#staticParameters['foo'].toUpperCase()"));
8989
parameters.add(new JpaParameter("foo", "bar", null));
9090
factory.setParameters(parameters);
@@ -97,7 +97,6 @@ public void testMapInputWithMappedExpressionResolveStatic() {
9797
@Test
9898
public void testListOfMapsInputWithExpression() {
9999
factory.setParameters(Collections.singletonList(new JpaParameter("spam", null, "foo.toUpperCase()")));
100-
@SuppressWarnings("unchecked")
101100
ParameterSource source = factory.createParameterSource(Arrays.asList(Collections.singletonMap("foo", "bar"),
102101
Collections.singletonMap("foo", "bucket")));
103102
String expression = "spam";
@@ -107,39 +106,39 @@ public void testListOfMapsInputWithExpression() {
107106

108107
@Test
109108
public void testPositionalStaticParameters() {
110-
List<JpaParameter> parameters = new ArrayList<JpaParameter>();
109+
List<JpaParameter> parameters = new ArrayList<>();
111110
parameters.add(new JpaParameter("foo", null));
112111
parameters.add(new JpaParameter("bar", null));
113112
factory.setParameters(parameters);
114113

115114
PositionSupportingParameterSource source = factory.createParameterSource("not important");
116115

117-
String position0 = (String) source.getValueByPosition(0);
118-
String position1 = (String) source.getValueByPosition(1);
116+
String position0 = (String) source.getValueByPosition(1);
117+
String position1 = (String) source.getValueByPosition(2);
119118

120119
assertThat(position0).isEqualTo("foo");
121120
assertThat(position1).isEqualTo("bar");
122121
}
123122

124123
@Test
125124
public void testPositionalExpressionParameters() {
126-
List<JpaParameter> parameters = new ArrayList<JpaParameter>();
125+
List<JpaParameter> parameters = new ArrayList<>();
127126
parameters.add(new JpaParameter(null, "#root.toUpperCase()"));
128127
parameters.add(new JpaParameter("bar", null));
129128
factory.setParameters(parameters);
130129

131130
PositionSupportingParameterSource source = factory.createParameterSource("very important");
132131

133-
String position0 = (String) source.getValueByPosition(0);
134-
String position1 = (String) source.getValueByPosition(1);
132+
String position0 = (String) source.getValueByPosition(1);
133+
String position1 = (String) source.getValueByPosition(2);
135134

136135
assertThat(position0).isEqualTo("VERY IMPORTANT");
137136
assertThat(position1).isEqualTo("bar");
138137
}
139138

140139
@Test
141140
public void testPositionalExpressionParameters2() {
142-
List<JpaParameter> parameters = new ArrayList<JpaParameter>();
141+
List<JpaParameter> parameters = new ArrayList<>();
143142

144143
parameters.add(new JpaParameter("bar", null));
145144
parameters.add(new JpaParameter(null, "#root.toUpperCase()"));
@@ -148,8 +147,8 @@ public void testPositionalExpressionParameters2() {
148147

149148
PositionSupportingParameterSource source = factory.createParameterSource("very important");
150149

151-
String position0 = (String) source.getValueByPosition(0);
152-
String position1 = (String) source.getValueByPosition(1);
150+
String position0 = (String) source.getValueByPosition(1);
151+
String position1 = (String) source.getValueByPosition(2);
153152

154153
assertThat(position1).isEqualTo("VERY IMPORTANT");
155154
assertThat(position0).isEqualTo("bar");

0 commit comments

Comments
 (0)