79374308

Date: 2025-01-21 12:03:46
Score: 2
Natty:
Report link

According to me initialy you are seding a get request and cache is storing the data so that it could retrieve the data directly on the second time get method is called with the same Id. Now what happens is you have a lazily loaded entity whose data is not stored by cache on the first time you made your get request, now on the second time the cache retrieves the lazily loaded entity data but because no data is present plus no active session is there to fetch this entity from database, it is throwning an LazyInitialisation exception.

How to solve it: 1-> use fetch = FetchType.EAGER loading 2-> don't send this lazyloaded entity as an response 3-> use a Dto Object and return this object instead of your entity, you can easily learn about it in web, using dto avoids a lot of exceptions.

Reasons:
  • Blacklisted phrase (1): How to solve
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: piyush Rawat