Unwrap user type when checking if type is JPA-managed.
We now unwrap the user type in JpaMetamodelMappingContext.shouldCreatePersistentEntityFor(…) to enable usage of proxy types when requesting a PersistentEntity. Previously, we checked against the proxy type which is not managed by the JPA meta-model. Closes #2383
This commit is contained in:
@@ -86,7 +86,7 @@ public class JpaMetamodelMappingContext
|
||||
*/
|
||||
@Override
|
||||
protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {
|
||||
return models.isMetamodelManagedType(type);
|
||||
return models.isMetamodelManagedType(type.getUserTypeInformation());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Collections;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
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;
|
||||
@@ -51,6 +52,7 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Jens Schauder
|
||||
* @author Mark Paluch
|
||||
* @since 1.3
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@@ -75,6 +77,16 @@ public class JpaMetamodelMappingContextIntegrationTests {
|
||||
assertThat(entity).isNotNull();
|
||||
}
|
||||
|
||||
@Test // GH-2383
|
||||
void considersProxiedTypes() {
|
||||
|
||||
JpaPersistentEntityImpl<?> directEntity = context.getRequiredPersistentEntity(User.class);
|
||||
assertThat(directEntity).isNotNull();
|
||||
|
||||
JpaPersistentEntityImpl<?> unproxiedEntitx = context.getRequiredPersistentEntity(UserProxy.class);
|
||||
assertThat(unproxiedEntitx).isNotNull().isSameAs(directEntity);
|
||||
}
|
||||
|
||||
@Test
|
||||
void detectsIdProperty() {
|
||||
|
||||
@@ -183,4 +195,17 @@ public class JpaMetamodelMappingContextIntegrationTests {
|
||||
static class Config {
|
||||
|
||||
}
|
||||
|
||||
static class UserProxy extends User implements HibernateProxy {
|
||||
|
||||
@Override
|
||||
public Object writeReplace() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LazyInitializer getHibernateLazyInitializer() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user