jpa一对多OneToMany关联查询;debug下lazy失效原因

jpa一对多实体类关联查询

package com.xx.xx.settings.domain;

import lombok.*;
import lombok.experimental.Accessors;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Table(name = "config_header")
@Entity
@Getter
@Setter
@Builder
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ConfigHeaderDO implements Serializable {

    private static final long serialVersionUID = 629506114082413243L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;


    @Column(name = "record_type")
    private String recordType;


    @Column(name = "description")
    private String description;


    @Column(name = "status")
    private Integer status;


    @Column(name = "gmt_create")
    private Date gmtCreate;

    @Column(name = "gmt_modified")
    private Date gmtModified;

    @Column(name = "version")
    private Integer version;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumns({
            @JoinColumn(name = "header_id", referencedColumnName = "id")
    })
    @Where(clause = "status = 1")
    private List<ConfigDetailDO> configDetails;

}

jpa一对多OneToMany关联查询;debug下lazy失效原因_第1张图片

@JoinColumn注解name属性就是要关联的column是被关联表中的关联字段,referencedColumnName属性就是本身表里去关联子表的字段;比如headeriddetail中的headerId关联,那么在header实体类中name=headerId,referencedColumnName =id.
jpa一对多OneToMany关联查询;debug下lazy失效原因_第2张图片

jpa一对多OneToMany关联查询;debug下lazy失效原因_第3张图片

debug下lazy失效原因

在idea debug模式下在实体类中使用
@OneToMany(fetch = FetchType.LAZY)
时,在get对应属性前断点,然后会发现懒加载失效了,这是因为在debug模式下,会自动进行级联查询

你可能感兴趣的:(Mysql,jpa,java,开发语言,后端)