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 8012853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:27:41+00:00 2026-06-04T19:27:41+00:00

I am developing a JavaEE6 based web application using JBoss7. In my application I

  • 0

I am developing a JavaEE6 based web application using JBoss7.
In my application I am injecting the EntityManager in my EJBs as:

class ForumServiceEJB
{
    @PersistenceContext(type=EXTENDED)
    private EntityManager em;

}

class TopicServiceEJB
{
    @PersistenceContext(type=EXTENDED)
    private EntityManager em;

}

The problem when I update some data using ForumServiceEJB’s EntityManager then the changes are made into DB but TopicServiceEJB’s EntityManager is not able to see those changes and the results are always fetched from Cache.

I am using ExtendedPerssisteenceContext as My Entities contain child Entity Collections of Lazy Loading type.

How can I use/Inject EntityManager of type ExtendedPersistenceContext and make different EntityManager in one EJB can still see the changes done by other different EJB EntityManagers?

Somewhere I read EntityManagers should be RequestScoped objects.

public class MyEntityManagerProducers {
 @Produces @RequestScoped 
 public EntityManager createDbEm() {
   return Persistence.createEntityManagerFactory("forumDb").
          createEntityManager();
 }

 public void disposeUdEm(@Disposes EntityManager em) {
   em.close();
 }

Is it the way to go?

  • 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-04T19:27:42+00:00Added an answer on June 4, 2026 at 7:27 pm

    I am using ExtendedPerssisteenceContext as My Entities contain child
    Entity Collections of Lazy Loading type.

    This is not a good reason to use EXTENDED. I would suggest you to make it default, which is TRANSACTION. And it’s good to make your EntityManager request-scoped, or method-scoped, in non-enterprise environment or when using application-managed persistence, as this is not a very heavy object to create. Moreover, neither using application-scoped EntityManager is a good idea, as it is not threadsafe.

    Having said that, as you are using JBoss, you should let the container handle the lifecycle of EntityManager, in case you are using JTA. Hence, just inject that with everything default

    Note:

    Only stateful session beans can have a container-managed, extended entity manager.

    Links:

    • http://javanotepad.blogspot.com/2007/08/managing-jpa-entitymanager-lifecycle.html
    • https://blogs.oracle.com/enterprisetechtips/entry/extended_persistence_context_in_stateful

    Suggestions:

    Your business method should know whether to load the children or not. But that’s the ideal case. A number of times we can’t say that and completely depends on the user input — we can’t predict that well. Therefore, there are two solutions available,

    1. make a separate AJAX call to load children
    2. Use the filter called open-session-in-view. I would prefer the former.

    Links:

    • https://community.jboss.org/wiki/OpenSessionInView
    • http://static.springsource.org/spring/docs/1.2.9/api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html
    • Why is Hibernate Open Session in View considered a bad practice?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a web application using Spring and Tomcat 7.0. When I test
I'm developing a web application using Java EE6 and JSF 2.0. I have a
I'm developing a web application at the moment. I'm using JSF 2 on a
I'm developing an application on GlassFish v3 which uses Suns-RI of JavaEE6 and JSF2.0,
Developing a desktop application based on Java + Swing I faced the problem of
Developing a network application, I have a Connection class that manages sending and receiving
This question came to me when developing using Eclipse. I use JBoss Application Server
I am developing a Java application that is to have two web interfaces: a
Developing an application using SWT to work in both Linux and Windows. I created
Background Developing a simple web application (Eclipse + JBoss + Apache Tomcat) to generate

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.