EJB Embeddable Objects - EJB(Enterprise JavaBeans)

What is EJB Embeddable Objects?

EJB 3.0 provides selection to embed JAVA POJO (Plain Old Java Object) into a creature bean and allows mapping column names with the method of the embedded POJO class. A java POJO to be embedded should be annotated as @Embeddable.

The beyond class can be embedded using @Embedded annotation.

Example Application

Let us form a test EJB application to test embedded objects in EJB 3.0.

Step Description
1 Create a project with a nameEjbComponentunder a packagecom.tWisdomjobs.entityas explained in theEJB - Create Applicationchapter. Please use the project created inEJB - Persistencechapter as such for this chapter to understand embedded objects in EJB concepts.
2 CreatePublisher.javaunder packagecom.Wisdomjobs.entityas explained in theEJB - Create Applicationchapter. Keep rest of the files unchanged.
3 CreateBook.javaunder packagecom.Wisdomjobs.entity. UseEJB - Persistencechapter as reference. Keep rest of the files unchanged.
4 Clean and Build the application to make sure business logic is working as per the requirements.
5 Finally, deploy the application in the form of a jar file on JBoss Application Server. JBoss Application server will get started automatically if it is not started yet.
6 Now create the EJB client, a console based application in the same way as explained in theEJB - Create Applicationchapter under topicCreate Client to access EJB.

Create/Alter Book Table

EJBComponent (EJB Module)





  • As soon as you deploy the EjbComponent project on JBOSS, notice the jobs log.
  • Jobs has automatically formed a JNDI entry for our session bean − LibraryPersistentBean/remote.
  • We will be using this lookup string to get remote business entity of type −com.Wisdomjobs.interceptor.LibraryPersistentBeanRemote

Jobs Application Server Log Output

EJBTester (EJB Client)


  • These properties are used to initialize the Initial Context entity of java naming service.
  • Initial Context object will be used to lookup stateless session bean.


EJBTester performs the following tasks −

  • Load properties from jndi.properties and initialize the Initial Context object.
  • In testInterceptedEjb () method, jade lookup is done with the name - "LibraryPersistenceBean/remote" to find the remote business object (stateless EJB).
  • Then the user is shown a library store User Interface and he/she is asked to enter a choice.
  • If the user enters 1, the system asks for book name and saves the book using stateless session bean add Book () method. Session Bean is storing the book in database.
  • If the user enters 2, the system retrieves books using stateless session bean get Books () method and exits.

Run Client to Access EJB

Establish EJBTester.java in development explorer. Right click on EJBTester class and choose run file.

Verify the following output in Net beans console.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

EJB(Enterprise JavaBeans) Topics