Spring-data-jpa -- if one-to-one and others-to-one annotations are used, an error solution will appear during Jackson's json String Conversion,
References:
Http://blog.csdn.net/remote_roamer/article/details/51330843
Http://blog.csdn.net/xiaodaiye/article/details/51118870
In spring-data-jpa, one-to-one and two-to-one annotations are used to produce json strings.
Find the following solutions after reading the information:
Add @ JsonManagedReference to the pojo of the master table to annotate the joined fields:
@ Onetovel (cascade = CascadeType. REFRESH, mappedBy = "ruleType", targetEntity = Rule. class) @ JsonManagedReferenceprivate Set rule;
Add @ JsonBackReference to the pojo of the sub-table to annotate associated fields.
@ ManyToOne (cascade = CascadeType. REFRESH, fetch = FetchType. EAGER) @ JsonBackReference @ JoinColumn (name = "TYPE_ID") private RuleType ruleType;
Then, Jackson is used to generate json
New ObjectMapper (). writeValueAsString (obj );