Skip to content

Commit c370425

Browse files
committed
Avoid strong proxy checks in test case for identifier access.
Under still to clarify circumstances a class processed by Hibernate might result in proxies *not* created for a otherwise proxied relationship. So far, our tests have relied on those cases always return a proxy reliably but some optimizations in Hibernate 6.2 (likely [0]) don't allow creating proxies reliably. Until we find a better way to reliably create a proxy we back off from strictly checking whether we deal with a proxy. Related tickets: #2899. [0] https://hibernate.atlassian.net/browse/HHH-15790
1 parent efd799c commit c370425

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

spring-data-jpa/src/test/java/org/springframework/data/jpa/mapping/JpaMetamodelMappingContextIntegrationTests.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919

20-
import java.util.Collections;
21-
2220
import jakarta.persistence.EntityManager;
2321

22+
import java.util.Collections;
23+
2424
import org.hibernate.proxy.HibernateProxy;
2525
import org.hibernate.proxy.LazyInitializer;
2626
import org.junit.jupiter.api.BeforeEach;
2727
import org.junit.jupiter.api.Test;
2828
import org.junit.jupiter.api.extension.ExtendWith;
29-
3029
import org.springframework.beans.factory.annotation.Autowired;
3130
import org.springframework.context.annotation.ComponentScan.Filter;
3231
import org.springframework.context.annotation.Configuration;
@@ -145,8 +144,10 @@ void lookingUpIdentifierOfProxyDoesNotInitializeProxy() {
145144
IdentifierAccessor accessor = entity.getIdentifierAccessor(loadedProduct);
146145

147146
assertThat(accessor.getIdentifier()).isEqualTo(category.getProduct().getId());
148-
assertThat(loadedProduct).isInstanceOf(HibernateProxy.class);
149-
assertThat(((HibernateProxy) loadedProduct).getHibernateLazyInitializer().isUninitialized()).isTrue();
147+
148+
if (loadedProduct instanceof HibernateProxy proxy) {
149+
assertThat(proxy.getHibernateLazyInitializer().isUninitialized()).isTrue();
150+
}
150151

151152
status.setRollbackOnly();
152153

0 commit comments

Comments
 (0)