I'm using spring-mvc and hibernate session-factory.
@Controller
|
-> @Service (@Transactional)
|
-> @Repository
I have 2 entities, User and Address.
User has a List<Address> with FetchType=LAZY.
If I add an Addressobject via user, within a @Controller, I get failed to lazily initialize a collection of role - could not initialize proxy - no Session exception.
But If I do this inside the service layer which is wrapped with @Transactional, operation works nicely.
I found out about hibernate proxies,...etc.
My question is, why @Controller cannot change an entity object which is retried from @Service layer. Because @Controller has no idea whether it is a hibernate proxy or anything else. To the @Controller it is just an object. So why I'm getting an error, if I change an entity object inside the @Controller. This is only happening to entity properties which are marked as FetchType=LAZY.