Creating A Stateless EJB

New session bean will be used to create and persist entities, later we will explore tables content for the created entities.

Create new stateless session EJB as described in Use An Entity Object (POJO) section.

Source folder: InheritanceHierarchies/src

Session Bean Type: Stateless

Bean Package: by.iba.ejb3.session

Bean Name: Manager

Open Manager.java file (Remote [Business] Interface) and add the following code:

	public void populate();
					

Open ManagerBean.java file (Bean Class) and add the following code:

	@PersistenceContext(unitName = "inheritance")
	private EntityManager manager;

	public void populate() {
		populateJoined();
		populateSingleTable();
		populateTablePerClass();
	}

	private void populateJoined() {
		by.iba.ejb3.joined.Person p = new by.iba.ejb3.joined.Person();
		p.setFirstName("Volha");
		p.setLastName("Zaikina");

		by.iba.ejb3.joined.Employee e = new by.iba.ejb3.joined.Employee();
		e.setFirstName("Mikalai");
		e.setLastName("Zaikin");
		e.setDepartment("IS");
		e.setEmail("nzaikin[at]iba.by");

		manager.persist(p);
		manager.persist(e);
	}

	private void populateSingleTable() {
		by.iba.ejb3.singletable.Person p = new by.iba.ejb3.singletable.Person();
		p.setFirstName("Volha");
		p.setLastName("Zaikina");

		by.iba.ejb3.singletable.Employee e = new by.iba.ejb3.singletable.Employee();
		e.setFirstName("Mikalai");
		e.setLastName("Zaikin");
		e.setDepartment("IS");
		e.setEmail("nzaikin[at]iba.by");

		manager.persist(p);
		manager.persist(e);
	}

	private void populateTablePerClass() {
		by.iba.ejb3.tableperclass.Person p = new by.iba.ejb3.tableperclass.Person();
		p.setFirstName("Volha");
		p.setLastName("Zaikina");

		by.iba.ejb3.tableperclass.Employee e = new by.iba.ejb3.tableperclass.Employee();
		e.setFirstName("Mikalai");
		e.setLastName("Zaikin");
		e.setDepartment("IS");
		e.setEmail("nzaikin[at]iba.by");

		manager.persist(p);
		manager.persist(e);
	}
					

Now InheritanceHierarchies EJB 3.0 project should look like this:

InheritanceHierarchies EJB 3.0 project

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine