Keeping Hibernate Session from Expiring via Annotations? — failed to lazily initialize a collection of role?

You need to do the following: 1) Let Spring manage your transaction: You can read more about it here: mkyong.com/spring/spring-aop-transaction... and here: static.springsource.org/spring/docs/3.0.... 2) Now the lazy loading: When you fetch object from bernate all its lazy associations are returned as proxy and then when you access proxy classes you get the exception because your bernate session is closed. The solution is to use open Session in View Filter/Interceptor. paulcodding.com/blog/2008/01/21/using-th... it will look exactly like this: Hope it helps.

Bernate sessions are different from web sessions and they don't expire. They get closed either manually by your code or by the infrastructure (Spring for example). In your case is not clear how your session gets created on the first place, since if you enter DAO without a session you would get completely different exception (No Session Bound to Thread).

So, somehow your session gets created and closed. My wild guess is that your DAO is made transactional either via @Transactional or via interceptors so session is initiated when you enter it and closed when you exit DAO method. In this case, putting @Transactional on your MVC method will work for as long as transaction propagation on DAO is set to PROPAGATION_REQUIRED.

Keep in mind, though, that you can't carry your collection outside of method annotated via @Transactional. For example you should not put it in http session. If that's a requirement, you may want to consider special DTO objects to copy data.

The solution I used was to use the @LazyCollection annotation on the collection in the DAO. @OneToMany(mappedBy = "", cascade = CascadeType. ALL) @LazyCollection(LazyCollectionOption.

FALSE).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions