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

  • Home
  • SEARCH
  • 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 6529955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:41:53+00:00 2026-05-25T09:41:53+00:00

I have been developing my web-app using JPA 2.0 implementation EclipseLink 2.2.0. I finally

  • 0

I have been developing my web-app using JPA 2.0 implementation EclipseLink 2.2.0. I finally got around to running multi-threaded code and I got this exception:

java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager.

The objects that have all the javax.persistence calls in my application are defined as application scoped, like this:

@Model
@ApplicationScoped
public class LocationControl implements Serializable {

    @PersistenceContext private EntityManager   em;
    @Resource           private UserTransaction utx;

    // etc

And of course all the managed beans (usually RequestScoped or ConversationScoped) that want to access the data base do so like this:

@Inject private LocationControl lc;

So my question is this: Did I get that Exception through the use of @ApplicationScoped DAO? I had thought that it would be more efficient that way, since the container would not have to be continually re-creating this object on every request if it did not have a scope, and the DAO has no state of its own. However if the EntityManager and UserTransaction object have to be separate instances for each user, then that would be a problem.

Alternatively, I could use syncrhonized on the DAO methods, but I think that would cause thread lockups in the container (GlassFish).

Any advice appreciated.

  • 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-05-25T09:41:54+00:00Added an answer on May 25, 2026 at 9:41 am

    @Model annotation was originally created to annotate request scoped beans, here is how it’s defined:

    @Named
    
    @RequestScoped
    
    @Stereotype
    
    @Target({TYPE, METHOD, FIELD})
    
    @Retention(RUNTIME)
    
    public @interface Model {}
    

    You can of course override ‘@RequestScoped’ with another annotation but ‘@ApplicationScoped’ it’s not a good choice as everyone in the application would modify the state of the same injected EntityManager. I think it would be best to leave it @RequestScoped in most cases, sometimes, for example for a login/logout data bean ‘@SessionScoped’ could be an option but I cannot see a scenario for ‘@ApplicationScoped’ dao.

    If you don’t want to use @Model at all and you use full Java EE container, then the stateless EJB ,as BalusC said, would be a great option for Dao too.

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

Sidebar

Related Questions

So I have been developing a small ASP.NET web app in C# for my
I have been developing web apps (primarily) using php and a bit of python,
I've been developing an asp.net web app using VS studio. I'm using SQL Server
We have been developing a DB web app which constantly queries an SQL store
I have been developing an app for iPad and consuming the Web Service in
I've been developing an iPhone web app on a Windows XP box using MobiOne
I've been developing web applications for 2 years now, and have been into simpler
I've been developing Web applications for a while now and have dipped my toe
I have been developing an app in VB.NET which requires a control object (for
I've been developing my first web based app for about two months now (I'm

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.