Springboot+Springdata-JPA多表联查时的溢栈问题
springdata-JPA实现一对一、一对多、关系
以简化的理发店会员信息管理系统为例,共有5个类,Barber(理发店)、Bill、Boss、Member、PatternConsumption(消费套餐)5个实体。
部分关系如下:
-
Barber与Boss为一对一关系,即一个老板对应一个店铺
-
Member与Barber为一对多关系,其中一为Barber
-
PatternConsumption与Barber为一对多关系,其中一为Barber
代码如下
Barber类
package infosys.bean.entity;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.Getter;
import lombok.ToString;
import javax.persistence.*;
import java.util.List;
/**
* @author aaaaaaa
*/
@ToString
@Data
@Entity
@JsonIgnoreProperties(value={"patternConsumptionList","memberList","boss","billList","idmemeber","idbarber","hibernateLazyInitializer","handler","fieldHandler"})
public class Barber {
@Id
@GeneratedValue
private Integer idbarber;
@Column(nullable = false)
private String name;
//@OneToOne(mappedBy = "barber", cascade = {CascadeType.MERGE, CascadeType.REFRESH})//, optional = false
@OneToOne(fetch=FetchType.LAZY,cascade = CascadeType.ALL)
@JoinColumn(name="idboss",referencedColumnName="idboss",nullable = false)
@ToString.Exclude
private Boss boss;
@Column(nullable = false)
private String address;
/*@OneToMany(mappedBy = "barber")
@JsonIgnoreProperties("barber")
@JSONField(serialize &#