Skip to content

Commit 39e72af

Browse files
committed
Fix build failures with Java 16.
A few test that used reflection to access the actual SQL executed by a Query object failed with `java.lang.reflect.InaccessibleObjectException: Unable to make field protected java.lang.reflect.InvocationHandler java.lang.reflect.Proxy.h accessible: module java.base does not "opens java.lang.reflect" to unnamed module 1b9e1916`. This change replaces the reflection used by a proper call to `unwrap`. Original pull request #2231
1 parent aa10c46 commit 39e72af

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/test/java/org/springframework/data/jpa/repository/query/PartTreeJpaQueryIntegrationTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
import javax.persistence.TemporalType;
3434

3535
import org.hibernate.Version;
36+
import org.hibernate.query.internal.QueryImpl;
3637
import org.junit.jupiter.api.BeforeEach;
3738
import org.junit.jupiter.api.Test;
3839
import org.junit.jupiter.api.extension.ExtendWith;
39-
4040
import org.springframework.data.domain.Page;
4141
import org.springframework.data.domain.PageRequest;
4242
import org.springframework.data.domain.Pageable;
@@ -107,11 +107,11 @@ void recreatesQueryIfNullValueIsGiven() throws Exception {
107107

108108
Query query = jpaQuery.createQuery((getAccessor(queryMethod, new Object[] { "Matthews", PageRequest.of(0, 1) })));
109109

110-
assertThat(HibernateUtils.getHibernateQuery(getValue(query, PROPERTY))).endsWith("firstname=:param0");
110+
assertThat(HibernateUtils.getHibernateQuery(query.unwrap(QueryImpl.class))).endsWith("firstname=:param0");
111111

112112
query = jpaQuery.createQuery((getAccessor(queryMethod, new Object[] { null, PageRequest.of(0, 1) })));
113113

114-
assertThat(HibernateUtils.getHibernateQuery(getValue(query, PROPERTY))).endsWith("firstname is null");
114+
assertThat(HibernateUtils.getHibernateQuery(query.unwrap(QueryImpl.class))).endsWith("firstname is null");
115115
}
116116

117117
@Test // DATAJPA-920
@@ -133,7 +133,7 @@ void shouldSelectAliasedIdForExistsProjectionQueries() throws Exception {
133133

134134
Query query = jpaQuery.createQuery((getAccessor(queryMethod, new Object[] { "Matthews" })));
135135

136-
assertThat(HibernateUtils.getHibernateQuery(getValue(query, PROPERTY))).contains(".id from User as");
136+
assertThat(HibernateUtils.getHibernateQuery(query.unwrap(QueryImpl.class))).contains(".id from User as");
137137
}
138138

139139
@Test // DATAJPA-1074
@@ -144,7 +144,7 @@ void isEmptyCollection() throws Exception {
144144

145145
Query query = jpaQuery.createQuery((getAccessor(queryMethod, new Object[] {})));
146146

147-
assertThat(HibernateUtils.getHibernateQuery(getValue(query, PROPERTY))).endsWith("roles is empty");
147+
assertThat(HibernateUtils.getHibernateQuery(query.unwrap(QueryImpl.class))).endsWith("roles is empty");
148148
}
149149

150150
@Test // DATAJPA-1074
@@ -155,7 +155,7 @@ void isNotEmptyCollection() throws Exception {
155155

156156
Query query = jpaQuery.createQuery((getAccessor(queryMethod, new Object[] {})));
157157

158-
assertThat(HibernateUtils.getHibernateQuery(getValue(query, PROPERTY))).endsWith("roles is not empty");
158+
assertThat(HibernateUtils.getHibernateQuery(query.unwrap(QueryImpl.class))).endsWith("roles is not empty");
159159
}
160160

161161
@Test // DATAJPA-1074

0 commit comments

Comments
 (0)