Hibernate: LazyInitializationException: failed to lazily initialize a collection of role. Could not initialize proxy - no Session
It seems that model is a detached entity.
Try to merge and perform operations on a merge instance:
@Override
public void process(Model model) {
...
Model mergedModel = session.merge(model);
mergedModel.addEntity(createEntity());
...
}
So as @Maciej Kowalski mentioned after first @Transactional
read of my model
it's already in deatached state and call to get entities
from another @Transactional
method failed with LazyInitializationException
.
I've changed my service a bit to get model
from database in the same transaction:
@Service
@Transactional
class ServiceImpl implements Service {
@Override
public void process(long modelId) {
...
Model model = modelDao.get(modelId);
model.addEntity(createEntity());
...
}
}
Now everything works as expected.