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
This commit is contained in:
committed by
Greg L. Turnquist
parent
1d3c8a224c
commit
13bb22cdbc
@@ -17,16 +17,15 @@ package org.springframework.data.jpa.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -145,8 +144,10 @@ class JpaMetamodelMappingContextIntegrationTests {
|
||||
IdentifierAccessor accessor = entity.getIdentifierAccessor(loadedProduct);
|
||||
|
||||
assertThat(accessor.getIdentifier()).isEqualTo(category.getProduct().getId());
|
||||
assertThat(loadedProduct).isInstanceOf(HibernateProxy.class);
|
||||
assertThat(((HibernateProxy) loadedProduct).getHibernateLazyInitializer().isUninitialized()).isTrue();
|
||||
|
||||
if (loadedProduct instanceof HibernateProxy proxy) {
|
||||
assertThat(proxy.getHibernateLazyInitializer().isUninitialized()).isTrue();
|
||||
}
|
||||
|
||||
status.setRollbackOnly();
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -74,8 +74,9 @@ public class PersistenceProviderIntegrationTests {
|
||||
Product product = categories.findById(category.getId()).get().getProduct();
|
||||
ProxyIdAccessor accessor = PersistenceProvider.fromEntityManager(em);
|
||||
|
||||
assertThat(accessor.shouldUseAccessorFor(product)).isTrue();
|
||||
assertThat(accessor.getIdentifierFrom(product).toString()).isEqualTo((Object) product.getId().toString());
|
||||
if (product instanceof HibernateProxy proxy) {
|
||||
assertThat(proxy.getHibernateLazyInitializer().isUninitialized()).isTrue();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user