Skip to content

Commit 13370f8

Browse files
committed
DATAREST-1322 - Fix proxy detection for Hibernate 5+ compatibility.
Switched to Spring Data Commons' ProxyUtils for a proxy detection mechanism that supports Hibernate 5 proxies.
1 parent 361be45 commit 13370f8

File tree

5 files changed

+12
-22
lines changed

5 files changed

+12
-22
lines changed

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/ProjectionDefinitionConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
import org.springframework.core.annotation.AnnotationUtils;
2929
import org.springframework.data.rest.core.projection.ProjectionDefinitions;
30+
import org.springframework.data.util.ProxyUtils;
3031
import org.springframework.util.Assert;
31-
import org.springframework.util.ClassUtils;
3232
import org.springframework.util.StringUtils;
3333

3434
/**
@@ -164,7 +164,7 @@ public Map<String, Class<?>> getProjectionsFor(Class<?> sourceType) {
164164

165165
Assert.notNull(sourceType, "Source type must not be null!");
166166

167-
Class<?> userType = ClassUtils.getUserClass(sourceType);
167+
Class<?> userType = ProxyUtils.getUserClass(sourceType);
168168
Map<String, ProjectionDefinition> byName = new HashMap<String, ProjectionDefinition>();
169169
Map<String, Class<?>> result = new HashMap<String, Class<?>>();
170170

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/event/AnnotatedEventHandlerInvoker.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,8 @@
3434
import org.springframework.core.ResolvableType;
3535
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
3636
import org.springframework.core.annotation.AnnotationUtils;
37-
import org.springframework.data.rest.core.annotation.HandleAfterCreate;
38-
import org.springframework.data.rest.core.annotation.HandleAfterDelete;
39-
import org.springframework.data.rest.core.annotation.HandleAfterLinkDelete;
40-
import org.springframework.data.rest.core.annotation.HandleAfterLinkSave;
41-
import org.springframework.data.rest.core.annotation.HandleAfterSave;
42-
import org.springframework.data.rest.core.annotation.HandleBeforeCreate;
43-
import org.springframework.data.rest.core.annotation.HandleBeforeDelete;
44-
import org.springframework.data.rest.core.annotation.HandleBeforeLinkDelete;
45-
import org.springframework.data.rest.core.annotation.HandleBeforeLinkSave;
46-
import org.springframework.data.rest.core.annotation.HandleBeforeSave;
47-
import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
37+
import org.springframework.data.rest.core.annotation.*;
38+
import org.springframework.data.util.ProxyUtils;
4839
import org.springframework.util.ClassUtils;
4940
import org.springframework.util.LinkedMultiValueMap;
5041
import org.springframework.util.MultiValueMap;
@@ -115,7 +106,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro
115106
@Override
116107
public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException {
117108

118-
Class<?> beanType = ClassUtils.getUserClass(bean);
109+
Class<?> beanType = ProxyUtils.getUserClass(bean);
119110
RepositoryEventHandler typeAnno = AnnotationUtils.findAnnotation(beanType, RepositoryEventHandler.class);
120111

121112
if (typeAnno == null) {

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/PersistentEntitiesResourceMappings.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import org.springframework.data.mapping.PersistentEntity;
2727
import org.springframework.data.mapping.PersistentProperty;
2828
import org.springframework.data.mapping.context.PersistentEntities;
29+
import org.springframework.data.util.ProxyUtils;
2930
import org.springframework.util.Assert;
30-
import org.springframework.util.ClassUtils;
3131

3232
/**
3333
* {@link ResourceMappings} for {@link PersistentEntities}.
@@ -63,7 +63,7 @@ public ResourceMetadata getMetadataFor(Class<?> type) {
6363

6464
Assert.notNull(type, "Type must not be null!");
6565

66-
type = ClassUtils.getUserClass(type);
66+
type = ProxyUtils.getUserClass(type);
6767

6868
if (cache.containsKey(type)) {
6969
return cache.get(type);
@@ -85,7 +85,7 @@ public ResourceMetadata getMetadataFor(Class<?> type) {
8585
MappingResourceMetadata getMappingMetadataFor(Class<?> type) {
8686

8787
Assert.notNull(type, "Type must not be null!");
88-
Class<?> userType = ClassUtils.getUserClass(type);
88+
Class<?> userType = ProxyUtils.getUserClass(type);
8989

9090
MappingResourceMetadata mappingMetadata = mappingCache.get(userType);
9191

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/BasePathAwareHandlerMapping.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@
4545
import javax.servlet.http.HttpSession;
4646
import javax.servlet.http.Part;
4747

48-
import org.springframework.core.annotation.AnnotationUtils;
4948
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
49+
import org.springframework.data.util.ProxyUtils;
5050
import org.springframework.http.HttpHeaders;
5151
import org.springframework.http.MediaType;
5252
import org.springframework.util.Assert;
53-
import org.springframework.util.ClassUtils;
5453
import org.springframework.util.StringUtils;
5554
import org.springframework.web.method.HandlerMethod;
5655
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
@@ -171,7 +170,7 @@ protected ProducesRequestCondition customize(ProducesRequestCondition condition)
171170
@Override
172171
protected boolean isHandler(Class<?> beanType) {
173172

174-
Class<?> type = ClassUtils.getUserClass(beanType);
173+
Class<?> type = ProxyUtils.getUserClass(beanType);
175174

176175
return type.isAnnotationPresent(BasePathAwareController.class);
177176
}

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
import org.springframework.data.rest.core.mapping.ResourceMappings;
3636
import org.springframework.data.rest.core.mapping.ResourceMetadata;
3737
import org.springframework.data.rest.webmvc.support.JpaHelper;
38+
import org.springframework.data.util.ProxyUtils;
3839
import org.springframework.http.HttpMethod;
3940
import org.springframework.http.MediaType;
4041
import org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor;
4142
import org.springframework.util.Assert;
42-
import org.springframework.util.ClassUtils;
4343
import org.springframework.util.CollectionUtils;
4444
import org.springframework.util.StringUtils;
4545
import org.springframework.util.StringValueResolver;
@@ -184,7 +184,7 @@ protected HandlerMethod handleNoMatch(Set<RequestMappingInfo> requestMappingInfo
184184
@Override
185185
protected boolean isHandler(Class<?> beanType) {
186186

187-
Class<?> type = ClassUtils.getUserClass(beanType);
187+
Class<?> type = ProxyUtils.getUserClass(beanType);
188188

189189
return AnnotationUtils.findAnnotation(type, RepositoryRestController.class) != null;
190190
}

0 commit comments

Comments
 (0)