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
0
votes
1 answer

Java Hibernate Session in View Merge loses Changes?

i have a Hibernate APP we are trying to implement Open Session in View Pattern with ZK i have a question Hibernate creates a session per thread and closes it but we have severals operations with [criteria and save or update] methods in one session…
javiut
  • 193
  • 6
  • 24
0
votes
0 answers

org.hibernate.LazyInitializationException: could not initialize proxy

Good Evening, i have an exception called org.hibernate.LazyInitializationException: could not initialize proxy - no Session it rises when i tries to get attributes from an ibject thta resides in the session, here's my JSP stmts that get parameters…
Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165
0
votes
2 answers

OpentransactionPerView instead @Transactional

I have a Java EE Application with Spring 3.1.1 and Hibernate 4.1. Now I wanted to speed up things and saw that the bottleneck is the opening + closing of multiple transactions in one request. Now I removed all @Transactional annotations and created…
wutzebaer
  • 14,365
  • 19
  • 99
  • 170
0
votes
0 answers

GWT RequestFactory Open Session InView workaround

We have entities (top-entity) with sub-entities and can't use Open Session In View Filter because we modify entities in our service layer but we don't wan't those changes to be persistent. We persist only what we want by calling dao.update! On the…
0
votes
1 answer

Access HttpServletRequest anywhere

I used to have an Open Session In Conversation Filter based on cookies for a JSF 2 app. Now I want to build the same mechanism but technology-agnostic. Reusing some code, I have written this in a class that extends…
ElderMael
  • 7,000
  • 5
  • 34
  • 53
0
votes
2 answers

Issues with OpenSessionInView

I have implemented Spring/Hibernate's OpenSessionInView Pattern for Lazy Loading. I am facing either "No Sessoon" or "2 or more sessions" issue. Let me know If I am missing any steps: Here are detail code fragments: Web.XML
0
votes
1 answer

Hibernate. Get lazy collection size on jsp

I am using Spring MVC with OpenSessionInViewFilter and trying to find best practice to get lazy collection size on jsp (without loading collection and LazyInitializationException). Any solutions?
0
votes
2 answers

Open Session in view for new version of Hibernate

I look at this, very popular page and see that it start with This page describes Hibernate 3.1.x and code shown here does not work in older versions. So my question very easy: how to implement behavior like this in newest versions of hibernate…
Divers
  • 9,531
  • 7
  • 45
  • 88
0
votes
1 answer

Difference between session per request and Open Sesson in view pattern

Folks, what's the difference between Open Session in View and Session per request pattern? I am using Spring MVC and Hibernate . I am not talking about the transaction demarcation here, for Session per request seems to be 1 session:1 tx. But for…
Achow
  • 8,600
  • 6
  • 39
  • 49
0
votes
1 answer

Implementation of Annotation Driven Transaction in Open-Session-In-View with Spring 3 and Hibernate 4

I am developing an application with Wicket-1.5.3, Spring-3.1.1 and Hibernate-4.1.1. I want to implement Open-Session-In-View Pattern where the Transaction will be Annotation Driven and the Application should net get any…
Tapas Bose
  • 28,796
  • 74
  • 215
  • 331
1 2 3 4
5