The method below results in the org.hibernate.LazyInitializationException being thrown and I'd appreciate help in understanding why. I'm using JPA 2/Hibernate & Spring.
JPA 2/Hibernate are using the default transaction persistence context, therefore, shouldn't the method below allow for lazy loading?
Note: daoWrapper is a convenience class that wraps entity manager methods; the class itself is also annotated with @Transactional.
Code:
@Transactional(readOnly=true)
public Response getGallery(@PathParam("id") int id) {
Gallery g = daoWrapper.findById(Gallery.class, id);
...
GalleryDto gDto = new GalleryDto();
...
// getImages() returns a collection of 'image' objects.
gDto.setImages(g.getImages());
return Response.ok(gDto).build();
}