When there is a one-to-many, multi-class relationship, use Hibernate to query and turn Jackson into JSON
For example, persistent class user
public class User implements java.io.serializable{private string ID; Private set<usertorole> Usertoroles=new hashset<usertorole> (0); Getter Setter ...}
Its hibernate configuration file User.hbm.xml
<id name= "id" type= "java.lang.String" > <column name= "id" length= "ten"/> <generator class= "Assigned" ; </generator></id><set name= "Usertoroles" table= "Usertorole" inverse= "true" lazy= "false" Fetch= " Select "> <key> <column name=" ID "/> </key> <one-to-many class=" Com.xxx.entity.Usert Orole "/></set>
and Persistence class Usertorole
public class Usertorole implements java.io.serializable{private string ID; private user user; Getter Setter ...}
By User.hbm.xml, the user class is associated with a one-to-many and Usertorole class, and in order to fetch the value of the Usertorole collection, it also sets the
Lazy= "false"
Run times wrong, dead loop, wait a long time before overflow stop.
Then Jackson's annotations are about to work.
Add annotations above the user property of the Usertorole class @jsonbackreference
That
public class Usertorole implements java.io.serializable{private string ID; @JsonBackReference Private User User; Getter Setter ...}
It's OK to run again. This is to prevent this infinite loop.
This article is from the "under the Tree Beast" blog, please make sure to keep this source http://shuxiayeshou.blog.51cto.com/4452347/1866766
Hibernate and Jackson