Questions tagged [open-session-in-view]

Open Session In View (OSIV) is pattern where persistence context (session) is open and available in the presentation layer and closed at the end of the HTTP request.

Open Session In View (OSIV) is pattern where persistence context (session) is open and available in the presentation layer and closed at the end of the HTTP request. This pattern became prominent with Spring/Hibernate so it was possible to traverse between ORM (Hibernate/JPA) entities in order to render them without getting the famous "LazyInitializationException" (LIE) from the Hibernate framework.

Pesistence context (session) may be open at the start of the request but there are solutions how to do it on demand - which is preferred if the session is not always necessary.

Pros of the OSIV usage are:

  • it's easy to make changes in the presentation layer without changing the service layer/business logic, if one can traverse to the information across entities (alternative is prefetch everything on the business layer)

Cons of the solution:

  • no clean separation of responsibilities,
  • presentation may fetch objects lazily, lower performance (without service layer to even know about it), often leads to famous N+1 select problem,
  • typically, transaction is closed at the end of the request, which is too late for business logic to treat exceptions (this can be solved using shorter transaction around the business layer call and not around the whole session)
70 questions
1
vote
3 answers

Hibernate Update Problems - OpenSessionInViewFilter

It's been about 5 hours trying to update an object through hibernate in my application using Spring MVC 3 and OpenSessionInViewFilter without any luck. I've possibly gone through all the threads available in StackOverflow and other forums! Hibernate…
Vishwas Shashidhar
  • 807
  • 2
  • 9
  • 23
1
vote
1 answer

OpenSessionInViewFilter cannot find WebApplicationContext

I know configuring OSIVF is a common pain point. I've read all the pages I could find over that last couple of days, but nothing seems to get me past this issue. I have succeeded in getting myself confused, tho. I'm trying to keep this config…
Steve s.
  • 301
  • 1
  • 4
  • 13
1
vote
1 answer

OpenSessionInViewFilter cannot be cast to javax.servlet.Filter

I'm getting an exception when I try to start my Java EE Spring+Hibernate application in Tomcat7. This used to work, but I think I screwed something up while migrating to Tomcat7. The exception is Mar 29, 2013 11:38:33 PM…
Marvo
  • 17,845
  • 8
  • 50
  • 74
1
vote
2 answers

Spring, Hibernate, Tiles, OpenSessionInViewFilter and LazyInitializationException

I received LazyInitializationException on jsp when tried to get access to colection which was lazy loaded: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role:…
Escander
  • 256
  • 3
  • 19
1
vote
1 answer

OpenSessionInViewInterceptor in a non web application

I have to use OpenSessionInViewInterceptor in a non-web application. I have configured OSV Interceptor as follows,
Janhavi
  • 55
  • 1
  • 5
0
votes
1 answer

Open Session in View with EJB

How can I do Open Session in View pattern with EJB??? I've found for Servlets, but not for EJB Thanks a lot!
joaosavio
  • 1,481
  • 3
  • 17
  • 20
0
votes
2 answers

WicketTester with Hibernate

I'm currently figuring out how to make my Wicket Application testable. Basically, it is a Wicket / Hibernate / Apache Derby setup. Hibernate is used as a filter (as seen on: http://community.jboss.org/wiki/OpenSessionInView / see…
Rob Audenaerde
  • 19,195
  • 10
  • 76
  • 121
0
votes
1 answer

Transaction does not rollback

I use OpenSessionInView in my application. My goal is to rollback all change in database in one method if any exception occurs. Here is my controller: @RequestMapping(value="/kartazadan.do", method=RequestMethod.GET ) …
Cichy
  • 1,319
  • 3
  • 20
  • 36
0
votes
1 answer

Handling LazyInitializationException with @Transactional

I have a SpringBoot/Spring Data JPA application. Until recently, we used the default Spring setting "open-in-view". I had to switch this setting off, because as the use cases were going more complexe, managing transactions became a nightmare.…
0
votes
0 answers

How to remove Open Session in View from Project?

We are using Springboot 2 and sometime ago we started facing HikariPool connection exhaustion issue. Upon Debugging we found out the that hibernate Open Session in View is by default enabled in Spring. Now my question is how do we disable it. As…
0
votes
1 answer

Open Session In View OSIV - Does this happen for every request / thread?

I have turned off the OSIV in a Spring project as I have been reading why it (controversially) may be a bit of an anti-pattern. Not wanting to poke that debate as I have seen it gets heated but I am more interested/lost in the technicals. Either…
Jcov
  • 2,122
  • 2
  • 21
  • 32
0
votes
1 answer

Thymeleaf lists.sort causes LazyInitializationException despite open session in view

I have a Sprint Boot project with open session in view. When I try to sort a list like this
0
votes
0 answers

OSIV enabled Spring Data JPA repository not running DML query when it's called from Spring Redis Subscriber but works when called as http web request

I have a Spring Boot micro-service which has an endpoint to delete the entry from a table. I am using Spring Data JPA to perform this. It works fine when I call the api, HTTP request sent and JPA repository deletes the data. OSIV is enabled which…
0
votes
2 answers

LazyInitializationException on bi-directional one-to-many relationship in Spring Boot

The following Spring Boot service method throws a Hibernate's LazyInitializationException when trying to add a Comment to a Post in post.addComment(comment) : @Service public class CommentService { @Autowired private…
Simeon Leyzerzon
  • 18,658
  • 9
  • 54
  • 82
0
votes
1 answer

integration testing of hibernate with OpenSessionInViewFilter paradigm

I use spring and hibernate with a ria technology called ZKOSS and use the OpenSessionInViewFilter paradigm, I have integration tests to test features like 1) Entity is loaded into the UI (has lazily loaded entities) 2) Updates are made to it on the…
Sudarshan
  • 8,574
  • 11
  • 52
  • 74