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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:05:47+00:00 2026-06-13T08:05:47+00:00

I am using Maven framework to build my project and EJB 3.0 is the

  • 0

I am using Maven framework to build my project and EJB 3.0 is the EJB specification. I have an EJB interface A and its corresponding EJB class B that implements A. The body of class B is shown below:

@Stateless
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
class B implements A{

      @PersistenceContext(unitName = "Draco-PU", type = PersistenceContextType.TRANSACTION)
  EntityManager entityManager;  

      //called post construct
      @PostConstruct
      public init(){

            //body of init method

      }

I have a non-EJB class in a different package under the same project. I want to instantiate class B in this class, so that the init() method and other annotations are automatically referred and I can give explicit call to other methods in the EJB class. Please help.

  • 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-13T08:05:48+00:00Added an answer on June 13, 2026 at 8:05 am

    You can’t do that. Either the caller of NonEJBClass.someMethod() needs to pass A to someMethod (because the caller injected or looked it up), or someMethod needs to do the lookup itself (probably in one of the “java:” namespaces). Otherwise, you need to change your bean so that it can be used by an unmanaged client, e.g.:

    Bean:

    @Stateless
    @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
    class B implements A {
        private EntityManager entityManager;  
    
        @PersistenceContext(unitName = "Draco-PU", type = PersistenceContextType.TRANSACTION)
        public void setEntityManager(EntityManager em) {
            entityManager = em;
        }
    
        @PostConstruct
        public init() {
            //body of init method
        }
    }
    

    Unmanaged client:

    B obj = new B();
    obj.setEntityManager(...);
    obj.init();
    

    So, you either allow the container to create the object (and it takes care of all the injection and initialization), or you create the object yourself (and then you take care of all the setter calls and initialization).

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

Sidebar

Related Questions

Im using maven to build a multi module project. But some projects are in
I am using maven to build applications. I have deployed a WAR file containing
We're using maven 2.1.0. I have multiple modules that are completely separate, but still
I'm currently using Maven to build my Rhino JavaScript project, download dependent libraries, and
I'm trying to use Maven to build a Flex project using the Sonatype flexmojos.
Using Maven to build my project under windows works fine, but when I build
I am using Maven, Jersey and Jetty server to build a web service interface.
I'm working on a project using Maven as tool. Within the project I have
I have a multi-module project using Maven. On one of the modules I have
I am using maven-shade-plugin for a simple maven project, the plugin successfully includes all

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.