i have a many-to-one class relationship that goes (other details snipped out):
note the FetchType being EAGER...
Code:
public class Customer{
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="customer_id")
@org.hibernate.annotations.IndexColumn(name="payPosition")
@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@OrderBy("paymentDate")
public List<CustomerPaymentHistory> getPaymentHistory() {
return paymentHistory;
}
}
however, when i try to iterate on the list,
Code:
//retrieve data
Customer cust = customerDao.findById(c1.getCustomerId());
Assert.assertNotNull(cust);
for(CustomerPaymentHistory cph : cust.getPaymentHistory()){
System.out.println("\t" + cph );
}
I get a no Session error which points to the for loop above considering that its not Lazily retrieved:
Quote:
performCustomerOperations(com.ifvi.rims.dao.test.CustomerDaoTest) Time elapsed: 0.976 sec <<< ERROR!
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:108)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:150)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
at com.ifvi.rims.entities.Customer$$EnhancerByCGLIB$$bad860c2.getPaymentHistory(<generated>)
at com.ifvi.rims.dao.test.CustomerDaoTest.performCustomerOperations(CustomerDaoTest.java:130)
What did I miss in here?
Hope the info above is enough to state my point. Thanks!