Could not write content: failed to lazily initialize a collection of role

This is the normal Hibernate behaviour

In one to many relations, hibernate loads the father entity (Catalog in your case) but it will load the children entities List (List items and List orders in your case) in a LAZY mode

This means you can't access to these objects because they are just proxies and not real objects

This is usefull in order to avoid to load the full DB when you execute a query

You have 2 solution:

  1. Load children entities in EAGER mode (I strongly suggest to you to not do it because you can load the full DB.... but it is something related to your scenario
  2. You don't serialize in your JSON the children entities by using the com.fasterxml.jackson.annotation.JsonIgnore property

Angelo


A third option which can be useful if you don't want to use EAGER mode and load up everything is to use Hibernate::initialize and only load what you need.

Session session = sessionFactory.openSession();
Catalog catalog = (Catalog) session.load(Catalog.class, catalogId);
Hibernate.initialize(shelf);

More information