Spring Data, LazyInitializationException which pattern to use?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
15 views
There is a Entity class Operation, containing a list of objects stages, marked with the annotation @ManyToMany.
For this class, the generated interface repositorie inherited from JpaRepository without any additional methods.
public interface extends JpaRepository OperationTypeRepository { }

CRUD is a service that implements some business logic, using this repository. The read method is implemented elementary
public OperationType read(Long id) { return repository.getOne(id); }

And finally, there is a controller that uses the service.
OtFromBase OperationType = typeCrudService.read(ot1.getId()); otFromBase.getOperStages();

When you try to refer to the stages via a getter, not important(FetchType=LAZY or EAGER) get a LazyInitializationException error. I generally understand what's going on. The question is how to avoid it. There must be some pattern that allows you to correct the situation.
by | 15 views

1 Answer

0 like 0 dislike
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Mar 26, 2019 by palebluedot
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
36,634 users