Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8582777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:22:39+00:00 2026-06-11T21:22:39+00:00

Our application consists of three parts: 1. A core module, which contains model and

  • 0

Our application consists of three parts:
1. A core module, which contains model and DAO classes and the spring configuration.
2. A web module, which uses the core package and is executed in a (portal) web environment.
3. A tasks module, which also uses the core package and is executed as a scheduled task (no web context)

We try to introduce the OpenEntityManagerInView pattern with the Spring Filter for the web module. As far as I understand it, the DAOs must not close the EntityManager because the filter does it. Furthermore, I would inject an EntityManager with @PersistenceContext instead of EntityManagerFactory with @PersistenceUnit (is that right?).

But how can I reuse the same core package with these modifications in the tasks module? There is no Filter which controles the lifecycle of the EntityManager.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:22:41+00:00Added an answer on June 11, 2026 at 9:22 pm

    OpenEntityManagerInViewFilter is usually used to complement Spring transaction management, as follows:

    • You define transaction boundaries in your code. Inside a transaction you can use EntityManager injected with @PersistenceContext (or Hibernate session obtained from getCurrentSession()). Also transactions define JPA Units of Work, i.e. all changes to persistent object you made inside a transaction will be propageted to the database automatically.

    • But sometimes you need to access the database outside of defined transaction (the most notable case is lazy loading when rendering a view). For this case you have OpenEntityManagerInViewFilter that allows you to access the database and use @PersistenceContext at any point during HTTP request processing.

    As you can see, OpenEntityManagerInViewFilter acts as a substitute for absent transaction, therefore you can run the same code without OpenEntityManagerInViewFilter if you do it inside a scope of transaction. So, you need to define transactons appropriately to make sure that all persistence-related code in your tasks module runs inside a transaction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our application has a service layer and a DAO layer, written as Spring beans.
After refactoring some service-layer classes in our java web application, i was asking myself
At our company we are developing an application that will consists of several modules.
Our application takes text from a web form and sends it via email to
Our desktop application consists of a Mono/.NET 3.5 back end that communicates via USB
The main window of our WPF application consists of 4 regions, arranged as 2x2
I am using a web application framework (Symfony 1.3.6), which follows the MVC pattern.
Our application is a Java-GWT application that uses Guice-Persist and Guice-Servlet extensively. We have
Our application stores records with shorter texts (strings of 100-1000 characters). It provides search
Our application is a bit slow to load at startup, i'm wandering myself if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.