diff --git a/build.gradle b/build.gradle
index 6c1a89ff55..aea632e2f4 100644
--- a/build.gradle
+++ b/build.gradle
@@ -65,7 +65,7 @@ ext {
groovyVersion = '3.0.10'
hamcrestVersion = '2.2'
hazelcastVersion = '5.1.1'
- hibernateVersion = '5.6.8.Final'
+ hibernateVersion = '6.1.1.Final'
hsqldbVersion = '2.6.1'
h2Version = '2.1.212'
jacksonVersion = '2.13.3'
@@ -759,7 +759,7 @@ project('spring-integration-jpa') {
exclude group: 'org.springframework'
}
testImplementation "com.h2database:h2:$h2Version"
- testImplementation "org.hibernate:hibernate-core-jakarta:$hibernateVersion"
+ testImplementation "org.hibernate.orm:hibernate-core:$hibernateVersion"
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
}
}
diff --git a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactory.java b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactory.java
index f118d51e7d..8e02be5fdc 100644
--- a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactory.java
+++ b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2022 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.
@@ -110,9 +110,9 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour
@Override
@Nullable
public Object getValueByPosition(int position) {
- Assert.isTrue(position >= 0, "The position must be non-negative.");
+ Assert.isTrue(position > 0, "The position must be non-negative.");
if (position <= this.parameters.size()) {
- JpaParameter parameter = this.parameters.get(position);
+ JpaParameter parameter = this.parameters.get(position - 1);
String parameterName = parameter.getName();
if (parameterName != null) {
return getValue(parameterName);
diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/JpaExecutorTests.java b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/JpaExecutorTests.java
index b9223cd15c..7226893084 100644
--- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/JpaExecutorTests.java
+++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/JpaExecutorTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-2022 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.
@@ -208,7 +208,7 @@ public class JpaExecutorTests {
@Test
public void testResultStartingFromThirdRecordForNativeQuery() {
final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
- jpaExecutor.setNativeQuery("select * from Student s");
+ jpaExecutor.setJpaQuery("select s from Student s");
jpaExecutor.setFirstResultExpression(new LiteralExpression("2"));
jpaExecutor.setBeanFactory(this.beanFactory);
jpaExecutor.afterPropertiesSet();
diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayIntegrationTests-context.xml b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayIntegrationTests-context.xml
index 53e5186906..c855310352 100644
--- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayIntegrationTests-context.xml
+++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayIntegrationTests-context.xml
@@ -63,12 +63,4 @@
-
-
-
-
diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayIntegrationTests.java b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayIntegrationTests.java
index d9cd6977fb..060ab9d30f 100644
--- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayIntegrationTests.java
+++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayIntegrationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-2022 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.
@@ -17,13 +17,12 @@
package org.springframework.integration.jpa.outbound;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.util.List;
import jakarta.persistence.EntityManager;
-import org.hibernate.TypeMismatchException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
@@ -34,7 +33,6 @@ import org.springframework.integration.jpa.test.entity.StudentDomain;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
-import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.test.annotation.DirtiesContext;
@@ -79,10 +77,6 @@ public class JpaOutboundGatewayIntegrationTests {
@Qualifier("findResultChannel")
private PollableChannel findResultChannel;
- @Autowired
- @Qualifier("invalidIdType")
- private SubscribableChannel invalidIdTypeChannel;
-
@Autowired
private EntityManager entityManager;
@@ -151,28 +145,9 @@ public class JpaOutboundGatewayIntegrationTests {
Message> receive = this.findResultChannel.receive(2000);
assertThat(receive).isNotNull();
- try {
- this.findAndDeleteChannel.send(message);
- }
- catch (Exception e) {
- assertThat(e).isInstanceOf(ReplyRequiredException.class);
- }
- }
- @Test
- public void testInvalidIdType() {
- Message message = MessageBuilder.withPayload(1).build();
- try {
- this.invalidIdTypeChannel.send(message);
- fail("PersistenceException expected");
- }
- catch (Exception e) {
- assertThat(e).isInstanceOf(MessageHandlingException.class);
- assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class);
- assertThat(e.getCause().getCause()).isInstanceOf(TypeMismatchException.class);
- assertThat(e.getCause().getMessage())
- .contains("Expected: class java.lang.Long, got class java.lang.Integer");
- }
+ assertThatExceptionOfType(ReplyRequiredException.class)
+ .isThrownBy(() -> this.findAndDeleteChannel.send(message));
}
}
diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayTests-context.xml b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayTests-context.xml
index 3e65fdb148..ca3ef9c0a4 100644
--- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayTests-context.xml
+++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayTests-context.xml
@@ -186,7 +186,7 @@
-
+
diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactoryTests.java b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactoryTests.java
index 6474d45a78..7b76e5a34f 100644
--- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactoryTests.java
+++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/support/parametersource/ExpressionEvaluatingParameterSourceFactoryTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2019 the original author or authors.
+ * Copyright 2002-2022 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.
@@ -24,7 +24,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.jpa.support.JpaParameter;
@@ -32,6 +32,8 @@ import org.springframework.integration.jpa.support.JpaParameter;
/**
*
* @author Gunnar Hillert
+ * @author Artem Bilan
+ *
* @since 2.2
*
*/
@@ -57,7 +59,6 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
@Test
public void testListOfMapsInput() {
- @SuppressWarnings("unchecked")
ParameterSource source = factory.createParameterSource(Arrays.asList(Collections.singletonMap("foo", "bar"),
Collections.singletonMap("foo", "bucket")));
String expression = "foo";
@@ -83,8 +84,7 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
@Test
public void testMapInputWithMappedExpressionResolveStatic() {
-
- List parameters = new ArrayList();
+ List parameters = new ArrayList<>();
parameters.add(new JpaParameter("spam", null, "#staticParameters['foo'].toUpperCase()"));
parameters.add(new JpaParameter("foo", "bar", null));
factory.setParameters(parameters);
@@ -97,7 +97,6 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
@Test
public void testListOfMapsInputWithExpression() {
factory.setParameters(Collections.singletonList(new JpaParameter("spam", null, "foo.toUpperCase()")));
- @SuppressWarnings("unchecked")
ParameterSource source = factory.createParameterSource(Arrays.asList(Collections.singletonMap("foo", "bar"),
Collections.singletonMap("foo", "bucket")));
String expression = "spam";
@@ -107,15 +106,15 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
@Test
public void testPositionalStaticParameters() {
- List parameters = new ArrayList();
+ List parameters = new ArrayList<>();
parameters.add(new JpaParameter("foo", null));
parameters.add(new JpaParameter("bar", null));
factory.setParameters(parameters);
PositionSupportingParameterSource source = factory.createParameterSource("not important");
- String position0 = (String) source.getValueByPosition(0);
- String position1 = (String) source.getValueByPosition(1);
+ String position0 = (String) source.getValueByPosition(1);
+ String position1 = (String) source.getValueByPosition(2);
assertThat(position0).isEqualTo("foo");
assertThat(position1).isEqualTo("bar");
@@ -123,15 +122,15 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
@Test
public void testPositionalExpressionParameters() {
- List parameters = new ArrayList();
+ List parameters = new ArrayList<>();
parameters.add(new JpaParameter(null, "#root.toUpperCase()"));
parameters.add(new JpaParameter("bar", null));
factory.setParameters(parameters);
PositionSupportingParameterSource source = factory.createParameterSource("very important");
- String position0 = (String) source.getValueByPosition(0);
- String position1 = (String) source.getValueByPosition(1);
+ String position0 = (String) source.getValueByPosition(1);
+ String position1 = (String) source.getValueByPosition(2);
assertThat(position0).isEqualTo("VERY IMPORTANT");
assertThat(position1).isEqualTo("bar");
@@ -139,7 +138,7 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
@Test
public void testPositionalExpressionParameters2() {
- List parameters = new ArrayList();
+ List parameters = new ArrayList<>();
parameters.add(new JpaParameter("bar", null));
parameters.add(new JpaParameter(null, "#root.toUpperCase()"));
@@ -148,8 +147,8 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
PositionSupportingParameterSource source = factory.createParameterSource("very important");
- String position0 = (String) source.getValueByPosition(0);
- String position1 = (String) source.getValueByPosition(1);
+ String position0 = (String) source.getValueByPosition(1);
+ String position1 = (String) source.getValueByPosition(2);
assertThat(position1).isEqualTo("VERY IMPORTANT");
assertThat(position0).isEqualTo("bar");