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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:38:00+00:00 2026-06-11T02:38:00+00:00

I have a session bean class that has some database operations. I need to

  • 0

I have a session bean class that has some database operations. I need to use the class with multiple database so I config ejb-jar.xml to create session beans from this class, each bean for each database. Here is the code.

public class UserEM
{
    /** The entity manager */
    @Resource(name="userEntityManager/em")
    private EntityManager em;

    public EntityManager getEntityManager()
    {
        return this.em;
    }

    ... Database operations using the `em` ...
}

And here is the ejb-jar.xml

 ...
  <enterprise-beans>
    <session>
      <ejb-name>UserEM1</ejb-name>
      <ejb-class>com.abc.app.dao.UserEM</ejb-class>
      <session-type>Stateless</session-type>

      <persistence-context-ref>
        <persistence-context-ref-name>userEntityManager/em</persistence-context-ref-name>
        <persistence-unit-name>DataSource1</persistence-unit-name>
      </persistence-context-ref>
    </session>
    <session>
      <ejb-name>UserEM2</ejb-name>
      <ejb-class>com.abc.app.dao.UserEM</ejb-class>
      <session-type>Stateless</session-type>

      <persistence-context-ref>
        <persistence-context-ref-name>userEntityManager/em</persistence-context-ref-name>
        <persistence-unit-name>DataSource1</persistence-unit-name>
      </persistence-context-ref>
    </session>
  </enterprise-beans>
</ejb-jar>
...

When I only create one session bean, it works as expected. BUT I create more than two, it throws an exception on deploy as:

Caused by: java.lang.IllegalArgumentException: JBAS011053: Incompatible conflicting binding at java:comp/env/userEntityManager/em source: org.jboss.as.jpa.injectors.PersistenceContextInjectionSource@937b07ef
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.addJndiBinding(ModuleJndiBindingProcessor.java:237)
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.deploy(ModuleJndiBindingProcessor.java:136)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

What is going on here. Can anyone help? Any suggestions or comments are appropriated.

Nawa

  • 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-11T02:38:02+00:00Added an answer on June 11, 2026 at 2:38 am

    After playing with it for a while I found the solution. Here is the code.

    And here is the ejb-jar.xml

     ...
      <enterprise-beans>
        <session>
          <ejb-name>UserEM1</ejb-name>
          <ejb-class>com.abc.app.dao.UserEM</ejb-class>
          <session-type>Stateless</session-type>
    
          <persistence-context-ref>
            <persistence-context-ref-name>userEntityManager/em1</persistence-context-ref-name>
            <persistence-unit-name>DataSource1</persistence-unit-name>
          </persistence-context-ref>
        </session>
        <session>
          <ejb-name>UserEM2</ejb-name>
          <ejb-class>com.abc.app.dao.UserEM</ejb-class>
          <session-type>Stateless</session-type>
    
          <persistence-context-ref>
            <persistence-context-ref-name>userEntityManager/em2</persistence-context-ref-name>
            <persistence-unit-name>DataSource2</persistence-unit-name>
          </persistence-context-ref>
        </session>
      </enterprise-beans>
    </ejb-jar>
    ...
    

    What I didn’t know was that we were not only declare two EJBs here but we are also declaring two persistence context reference names which have to be unique in the application. Another word the value in ‘persistence-context-ref-name’ must also be unique. Once this is done the application is deployable and two session beans are created with different data source. The bean can be looked up with JNDI.

    Cheers,

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

Sidebar

Related Questions

I have something like that: faces-config.xml <managed-bean> <managed-bean-name>aBean</managed-bean-name> <managed-bean-class>some.pack.Bean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> I have a
What would a stateless session bean provide over just a regular class that has
I have an EJB3 stateless session bean that uses some other ejbs to do
i have an managed bean(session scope) like this: class Home {// as homeBean public
I have a session scoped managed bean called MyController. It has a reference to
I am reading about EJB Session Bean. I have worked mostly on spring and
i have created a demo application Using JSF & EJB 3.0 (Stateless session bean
I have a bean that describes my session factory. I only want to load
I have a dataTable which has a value of a bean class which looks
I have a Controller bean (SearchController) that has two managed bean as managed properties

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.