JPA Lazy Loding не работает в один ко многим - PullRequest
0 голосов
/ 20 января 2020

JPA отложенная загрузка не работает в @OneToMany(fetch=FetchType.LAZY ассоциации. Необходимо только загрузить родительский объект без дочернего объекта

    Parent Object - Emp

        @MappedSuperclass
        public class Emp implements Serializable {

        @Basic(optional = false)
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Id
        @Column(name = "emp_id", unique = true, nullable = false,length = 10)
        public BigInteger getEmpId() {
            return empId;
        }

        public void setEmpId(BigInteger empId) {
            this.empId = empId;
        }


        @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE},fetch=FetchType.LAZY)
        @JoinColumn(name = "ll_id", nullable = false , insertable = true)
        @PrivateOwned
        public List<DocumentData> getDocumentDataList() {
        return documentDataList;
        }
        }

Child - DocumentData - it has parent table primary key.

public class DocumentData implements Serializable {

    protected static final long serialVersionUID = 1L;

    private BigInteger documentId;
    private BigInteger empId;

    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column(name = "doc_id", unique = true, nullable = false,length = 10)
    public BigInteger getDocumentId() {
        return DocumentId;
    }

    public void setDocumentId(BigInteger documentId) {
        this.documentId = documentId;
    }

    @Column(name = "emp_id",length = 10)
    public BigInteger getEmpId() {
        return empId;
    }

    public void setEmpId(BigInteger empId) {
        this.empId = empId;
    }   
}

SQL запрос - выберите o из EMPData o, где 1 = 1 - проблема заключается в загрузке родительского объекта с дочерним объектом. Есть ли способ загрузить только родительский

...