Hi,
I have an EmailForm Object which have mapped one-to-many Lazy Collection with EmailFormDetails object.
Actually i required to retrieve the collection of EmailForm Object with pre initialized EmailFormDetails.
is that any way i can simplify the code or need to iterate each Email Form Object and apply Hibernate.initialize(EmailForm.getEmailFormDetails()).
Also how the performance if i approach this way since the collection of objects may around 20000+ records sometimes.
Please help on this.
Code:
EmailForm.java
=============
@OneToMany(mappedBy = "emailForm", fetch = FetchType.LAZY)
@Cascade(CascadeType.ALL)
private Set<EmailFormDetail> emailFormDetailList = new HashSet<EmailFormDetail>();
EmailFormDetail.java
===============
@ManyToOne
@JoinColumn(name = "EMAIL_FORM_ID")
private EmailForm emailForm;
Service API
public List<EmailForm> getAllEmailFormAndDetailsDataByDates(Date fromDate,Date toDate)
throws ApplicationException {
logger.info("findAllBetweenDates()-fromDate:" + fromDate + "toDate:"
+ toDate);
List<EmailForm> toReturn = null;
try {
toReturn = getEmailFormDAO().findAllBetweenDates(fromDate,
DateUtil.getInstance().adjustDays(toDate, 1));
//Hibernate.initialize(toReturn.size()); //NOT Works
//This is working.but any other better way we have?
for(EmailForm emailForm : toReturn)
Hibernate.initialize(emailForm.getEmailFormDetailList());
} catch (DBException e) {
throw new ApplicationException(e);
}
return toReturn;
}