Hi guys I am new to Hibernate and JPA
I wrote some functions, initially, I set fetch = FetchType.LAZY in the entity class. But it gave me error: "org.hibernate.LazyInitializationException: could not initialize proxy - no Session"
@OneToMany(cascade = CascadeType.ALL, mappedBy = "logins", fetch=FetchType.LAZY,targetEntity=Invoice.class)
public List<Invoice> getInvoiceList() {
return invoiceList;
}
public void setInvoiceList(List<Invoice> invoiceList) {
this.invoiceList = invoiceList;
}
Then I changed it to fetch = FetchType.EAGER, it worked fine..... I am wondering what happen if I don't declare FetchType, does Hibernate determine itself which method to use? Or is it defaulted by EAGER??
@OneToMany(cascade = CascadeType.ALL, mappedBy = "logins", fetch=FetchType.EAGER,targetEntity=Invoice.class)
public List<Invoice> getInvoiceList() {
return invoiceList;
}
public void setInvoiceList(List<Invoice> invoiceList) {
this.invoiceList = invoiceList;
}
THANKS!!!!!!!!!