Inside the following controller
@Transactional
@PostMapping(PATH_VARIABLE)
public void assignStuff(
@PathVariable final long someNo,
@PathVariable final long someId)
throws AccessDeniedException, ValidationException, ResourceNotFoundException
{
final Set<SomeEntity> createdEntities = someService.assignSomething(
resolveData(someNo, someId)
);
if (CollectionUtils.isNotEmpty(createdEntties))
{
anotherService.publishPackageDataChangeEvent(someNo);
}
}
the following exception is thrown
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: someEntity, could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:582)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:201)
at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:561)
at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:132)
at org.hibernate.collection.internal.PersistentSet.iterator(PersistentSet.java:163)
at java.util.Spliterators$IteratorSpliterator.estimateSize(Spliterators.java:1821)
at java.util.Spliterator.getExactSizeIfKnown(Spliterator.java:408)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at aThirdService.thingsChanged(SomeCalculator.java:61)
From other questions, it seems like this should be fixed with @Transactional, right? So why does it still occur?