We’re sorry. We could not find a match for your search.

We suggest you try the following to help find what you’re looking for:

  • Check the spelling of your keyword search.
  • Use synonyms for the keyword you typed, for example, try "application" instead of "software."
  • Start a new search.
Cloud Account Sign in to Cloud
Oracle Account

An Introduction to the Enterprise JavaBeans 3.0 (EJB 3) Specification

Entity Beans

An EJB 3.0 entity is a lightweight persistent domain object. Entity beans are marked with the @Entity annotation, and all properties/fields in the entity bean class not marked with the @Transient annotation are considered persistent. Entity bean persistent fields are exposed through JavaBean-style properties or just as public/protected Java class fields.

Entity beans can use helper classes for representing entity bean state, but instances of these classes don't have a persistent identity. Instead, their existence is tied strongly to the owning entity bean instance; also these objects are not shareable across entities.

Home interface

Entity beans do not need home interfaces.

Business interface

Entity beans do not need business interfaces. They are optional.

Entity class

  • The entity class must be annotated with the entity annotation or denoted in the XML descriptor as an entity.
  • The entity class must have a no-arg constructor. The entity class may have other constructors as well.
  • The no-arg constructor must be public or protected.

Persistent fields and properties

For single-valued persistent properties, the method signatures are:

  • T getProperty()
  • void setProperty(T t)

Code sample

As you can see from the following code sample, an entity bean is annotated with a @Entity tag. In the sample, we have some member variables and their corresponding getters and setters. Also the code sample shows how to annotate the CMR relationship.

A one-to-many relationship is shown using the @OneToMany tag. In this example, the Customer bean has a one-to-many relationship with the Orderscode> bean (one customer can have multiple orders).

Similarly, Customercode> has a many-to-many relationship with the Phonescode> bean. Some business methods will be defined in the business interface and implemented in the bean, for example, addPhone() which adds a phone record and associates it with the customer:

    public class Customer implements Serializable {
      private Long id;
      private String name;
      private Address address;
      private Collection orders = new HashSet();
      private Set phones = new HashSet();
      // No-arg constructor
      public Customer() {}
      public Long getId() {
        return id;
      public void setId(Long id) {
        this.id = id;
      public String getName() {
        return name;
      public void setName(String name) {
       this.name = name;
      public Address getAddress() {
        return address;
      public void setAddress(Address address) {
        this.address = address;
      public Collection getOrders() {
        return orders;
      public void setOrders(Collection orders) {
        this.orders = orders;
      public Set getPhones() {
        return phones;
      public void setPhones(Set phones) {
        this.phones = phones;
      // Business method to add a phone number to the customer
      public void addPhone(PhoneNumber phone) {
        // Set the phone's ref to this customer