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

How to close & open a new Hibernate Session in case of Exception

Context/Set-Up We are using open-session-in-conversation-filter pattern in our application w/ Spring & Hibernate integration. We are using Springs declarative transaction mgmt using the…
0
votes
0 answers

Keep persist/merge after a ConstraintViolationException using JPA

How can I merge and update an entity after a ConstraintViolationException using JPA + Hibernate and Open Session in View strategy? userTransaction.begin(); try { em.persist(entity); } catch (PersistenceException ce){ …
Pablo Souza
  • 863
  • 2
  • 11
  • 25
0
votes
1 answer

OpenSessionInView vs. Transactional? (Spring/Hibernate/JPA)

I have a JPA entity with Lazy loaded collection on it. I do not need the collection every time. @Entity(name = "Foo") @Access(AccessType.FIELD) @Table(name = "TEST", schema = "TEST") public class Foo implements Serializable { private static…
0
votes
1 answer

PersistenceManager and Open Session In View

my java skills are a bit rusty and I'm wondering how I can implement Open Session In View pattern for the PersistenceManager called from a servlet in a google app engine environment. I have some singleton which handles the PersistenceManagerFactory,…
0
votes
1 answer

Spring.NET + NHibernate - Multiple (Distinct) Databases with OpenSessionInView

In my web application, I have 2 totally different databases - one that's being used mostly by a CMS from which we'd like to get page information on non CMS pages on the same website, & one that contains totally different data. Is it possible to use…
0
votes
1 answer

OSIV pattern - pro's and con's ? general question about OSIV and views

I'm in the planning stages of a web site project and deciding on whether to go for OSIV and not use dao(eao)/dto (used dao/dto for an existing project) im wondering if, with OSIV, the entities should be accessible in the view (for example, with…
0
votes
1 answer

Caching lazy loaded Collection of a lazy loaded relation from open-session-in-view

I have this situation (details at the bottom): X is a hibernate entity X.y is a lazy-loaded reference to Y, another hibernate entity Y.z is a lazy-loaded, cached collection of hibernate entities Z In a post-transaction Spring bean, within…
0
votes
0 answers

Manager EntityManager thought JSF lifecycle

Well, i'm trying to creating the Pattern "OpenView Session in View" manually, without Spring Framework. My ideia is open the EntityManager SESSION in Restore View Phase and closes in Render Response Phase, using a…
Ronaldo Lanhellas
  • 2,975
  • 5
  • 46
  • 92
0
votes
1 answer

Open EntityManager in View in JPA for Java EE

I am searching for how to implement Open EntityManager In View pattern in JPA. However all I can find is for Hibernate (Open Session In View) or Spring. Could any of you give an example (with code if possible) on how to implement Open EntityManager…
Aliuk
  • 1,249
  • 2
  • 17
  • 32
0
votes
0 answers

OpenSessionInView isn't starting, spring, hibernate

Hi everyone I have a problem with OpenSessionInViewFilter, this filter isn't starting at all. It's third day my torture with this, I don't have any ideas how to solve it, I have read many many questions and answer about this but nothing helped…
szymon_prz
  • 540
  • 3
  • 14
0
votes
0 answers

OpenSessionInViewFilter and object in session - Spring MVC

I'm having a problem with OpenSessionInViewFilter and objects described in Sections, to do in a given request, occurs: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: ... , could not initialize proxy - no…
0
votes
2 answers

Updating an object in hibernate with OpenSessionInView filter

I am trying to update an object in hibernate but I don't understand why it is not getting updated in the db. Can anyone please help? Controller class package com.petclinic.controller; import com.petclinic.ClinicService; import…
underdog
  • 4,447
  • 9
  • 44
  • 89
0
votes
1 answer

Hibernate 4 + Spring 3, No Inserts or Updates

In order to work around Hibernate bug HHH-2763, I'm trying to update my app from Hibernate 3 to Hibernate 4. It seemed to have gone smoothly until I realized that while my application can read data, it never seems to do inserts or updates. I…
Marvo
  • 17,845
  • 8
  • 50
  • 74
0
votes
1 answer

logging hibernate queries with log4j when using servlet filter for open session in view pattern

First of all thank you for taking the time to read my question. I'll start with my environment: Primefaces 3.5 Hibernate 4.3.2 Glassfish 3.1.2 My problem is this: I want to log the sql queries hibernate does using log4j(and the parameters bound to…
Andrei Zafiu
  • 501
  • 6
  • 17
0
votes
1 answer

Java Hibernate OpenSession in View Avoid fetch on Controller

we have a APP in Hibernate lately we start using Open Session in View in our DAO we fetch the data we really need.. we dont close the session but later in our controller in any operation on the Entity Hibernate is fetching the Data from the DB i…
chiperortiz
  • 4,751
  • 9
  • 45
  • 79