I have an small console application and I am using spring-data-jpa with hibernate. I really can not figure out how to lazy initialize collections when using spring-data-jpa
This worked for me:
@Component
public class Test {
@Inject
OrderDAO orderDAO;
@PersistenceUnit
private EntityManagerFactory emf;
@PostConstruct
public void test(){
EntityManager em= emf.createEntityManager();
for (Order o:orderDAO.findAll()){
o=em.find(o.getClass(),o.getId());
System.out.println(o.getLazyField());
}
em.close();
}
}