问题
I am using following dependencies -
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.1.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.8.0.M1</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>2.3.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate4</artifactId>
<version>2.5.0-rc1</version>
</dependency>
And Find that some ManyToOne Links (those whose corresponding Repositories dont have Excerpt Projections) even though show in Hibernate Trace are extracting results but don't render JSON results on screen and presents only blank page until I choose one of its projections in query param.
no output but query are shown in log returning result with Fetch Type as LAZY
http://localhost:8585/app/userLanguages/8/user
get JSON as expected on screen with user detail as well
http://localhost:8585/app/userLanguages/8/user?projection=summary
get output with Fetch Type as EAGER
http://localhost:8585/app/userLanguages/8/user
I have also enabled pretty print for printing formatted JSON output for custom REST urls, hoping this should not cause any issue.
<mvc:annotation-driven>
<mvc:message-converters>
<bean id="jacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="prettyPrint" value="true" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
Also the entities have following annotations -
@AccessType(Type.PROPERTY)
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE)
Projections used above were not excerpt projections
回答1:
After some debugging found out that this is happening due to UserResourceProcessor. I had tried adding some extra links for pointing to custom REST URL through below. Once I commented @Component annotation, and kept only @AccessType(Type.PROPERTY) annotation in Entity, even lazy load URL work as intended. But, I will need the custom links and this is an issue ..
@Component
public class UserResourceProcessor implements ResourceProcessor<Resource<User>> {
public static final String CANCEL_REL = "cancel";
public static final String UPDATE_REL = "update";
@Autowired
private EntityLinks entityLinks;
@Override
public Resource<User> process(Resource<User> resource) {
User user = resource.getContent();
resource.add(entityLinks.linkForSingleResource(user).withRel(CANCEL_REL));
resource.add(entityLinks.linkForSingleResource(user).withRel(UPDATE_REL));
return resource;
}
}
来源:https://stackoverflow.com/questions/27647672/blank-screen-even-though-log-has-results-for-manytoone-lazy-associated-resource