How to use the EJB3 Entity Data Type

This chapter demonstrates how to use the EJB3 Entity Data type. Perform the following steps to prepare and use an Entity Data type in Infinity:

For general details on using Entity Bean data and Session Bean applications refer to chapters Using Entity Bean Data and Session Bean Applications accordingly.

You can download the example model and source files used for this example from here:

Prepare the Database

To prepare the database do the following:

  1. Create the Table and Sequences
  2. Register the Data Source

Create the Table and Sequences

Start by creating the table and sequences via the following command:

create sequence person_seq START WITH 1 INCREMENT BY 50;

Note that you can also generate them via JPA.

Register the Data Source

Create a data source under the JNDI name jdbc/sample-db. Make sure that it is an XA data source.

Create an Entity Bean Class

Create the following entity bean class. You can also find this class in the example sources zip file, which you can download from the link mentioned above.

package org.eclipse.stardust.examples.entity;

import javax.persistence.Entity;
import javax.persistence.Id;

import javax.persistence.GeneratedValue;
import javax.persistence.SequenceGenerator;
import javax.persistence.GenerationType;

@SequenceGenerator(name="person_seq", initialValue=1, allocationSize=50)
public class Person  {
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="person_seq")
   private Long id;
   private String name;
   private String vorname;
   public Long getId() {
      return id;
   public void setId(Long id) { = id;
   public String getName() {
      return name;
   public void setName(String name) { = name;
   public String getVorname() {
      return vorname;
   public void setVorname(String vorname) {
      this.vorname = vorname;
   public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(">>> Person id: ").append(id).append(" | vorname: ").append(vorname);
   sb.append(" | name: ").append(name).append(" | hashCode: ").append(hashCode());
   return sb.toString();

Create a persistence.xml

Create the following persistence.xml in the WEB-INF folder of your Web application:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
	xmlns="" xmlns:xsi=""
	<persistence-unit name="WebLogicCustomerPU"

			<!-- Deactivate Cache for the moment. Configure to your needs -->
			<property name="eclipselink.cache.shared.default" value="false" />
			<property name="eclipselink.cache.size.default" value="0" />
			<property name="eclipselink.cache.type.default" value="None" />

Update the Deployment Descriptor

Add to every @prodcutnameshort@ bean in the deployment descriptor (ejb-jar.xml) the following fragment to publish the entity manager name:

      <persistence-context-ref><!-- java:comp/env/userEntityManager/WebLogicCustomerPU -->

Create a Backing Bean

Create the backing bean to be used in the Session Bean application. You can also find these classes in the example sources zip file, which you can download from the link mentioned above.

package org.eclipse.stardust.examples.service;

import org.eclipse.stardust.examples.entity.*;

public interface TestService {

   public Person createPersonEntity();

   public Person changePerson(Person p);

package org.eclipse.stardust.examples.service;

import javax.ejb.Remote;
import javax.ejb.Stateful;

import org.eclipse.stardust.examples.entity.Person;

@Stateful(mappedName = "ejb/TestService")
public class TestServiceBean implements TestService {

   public Person createPersonEntity() {

      Person p = new Person();


      return p;

   public Person changePerson(Person p) {

      System.out.println("Original: " + p);

      System.out.println("Changed: " + p);
      return p;

Create a Model

Create a model with an entity data and session bean applications as described in the following sections or import the model provided in the example zip file if downloaded from the link mentioned above.

Setting for the Entity Data

Create an entity data with the following settings:

Entity Data
Figure: Entity Data settings

Settings for the Session Bean Applications

Create two session bean applications with the following settings:

Session Bean Application
Figure: Session Bean Application settings

Create the Model Workflow

Now create appropriate workflow as for example in the following screenshot:

Model Workflow
Figure: Example Model Workflow