Lazy loading under multi-view processing

One of the most common problems encountered recently is the problem that lazy loading cannot get the value when rendering View. There are two proxy modes for lazy loading processing objects, jdk dynamic proxy [default] and cglib weaving bytecode proxy.
HTTP Status 500 - Unable to locate object to be marshalled in model: {member=memberid|1 name|lily phone|1356874584 email|[email protected], org.springframework.validation.BindingResult.member=org.springframework.validation. BeanPropertyBindingResult: 0 errors}
org.springframework.web.servlet.view.xml.MarshallingView.renderMergedOutputModel(MarshallingView.java:104)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
org.springframework .web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet. java:915)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811) The
above is the error when returning the xml view. The

above is the object information, the returned object is encapsulated by lazy loading, and an error will be reported when the view takes a value
		<dependency>
		      <groupId>com.fasterxml.jackson.datatype</groupId>
		      <artifactId>jackson-datatype-hibernate3</artifactId>
		      <version>2.0.0</version>
		</dependency>

Then find fasterXML, which is used to handle lazy loading when json data is displayed, but xml has not yet found a module with similar functions.
<property name="defaultViews">
            <list>
            	<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
            		<property name="objectMapper">
	                    <bean class="org.carryli.common.hibernate.MyObjectMapper" />
	                </property>
            	</bean>
        </list>
</property>


It seems that spring uses fasterxml to handle lazy loading in 3.2
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.hibernate3.Hibernate3Module;

@Component
public class MyObjectMapper  extends ObjectMapper {

	public MyObjectMapper() {
		Hibernate3Module hbm = new Hibernate3Module();
		hbm.enable(Hibernate3Module.Feature.FORCE_LAZY_LOADING);

		registerModule(hbm);
		configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
	}

	public void setPrettyPrint(boolean prettyPrint) {
		configure(SerializationFeature.INDENT_OUTPUT, prettyPrint);
	}
}

the above for the record

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326869582&siteId=291194637