This discussion is archived
3 Replies Latest reply: Oct 25, 2012 6:41 AM by user696 RSS

How to instantiate an EJB class in a non-EJB class?

950731 Newbie
Currently Being Moderated
Hi,

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. How can I look up the EJB class for accessing the methods? Please help.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points