EJB With Remote Interface : Remote Local Interface « EJB3 « Java Tutorial

File: EmployeeBean.java

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public class EmployeeBean implements EmployeeServiceLocal, EmployeeServiceRemote {
  @PersistenceContext(unitName="EmployeeService") private EntityManager manager;
  public void doAction(){
    Customer cust = new Customer();

    cust = manager.find(Customer.class,cust.getId());

File: EmployeeServiceLocal.java

import javax.ejb.Local;
import javax.jws.WebParam;

public interface EmployeeServiceLocal {
  public void doAction();


File: EmployeeServiceRemote.java

import javax.ejb.Remote;

public interface EmployeeServiceRemote {
  public void doAction();

File: Customer.java

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Table(name = "CUSTOMER_TABLE")
public class Customer implements java.io.Serializable {
  private int id;

  private String lastName;

  private String firstName;

  private Date timeCreated = new Date();

  @Column(name = "CUST_ID")
  public int getId() {
    return id;

  public void setId(int pk) {
    id = pk;

  public String getLastName() {
    return lastName;

  public void setLastName(String lastName) {
    this.lastName = lastName;

  public String getFirstName() {
    return firstName;

  public void setFirstName(String firstName) {
    this.firstName = firstName;

  public Date getTimeCreated() {
    return timeCreated;

  public void setTimeCreated(Date time) {
    timeCreated = time;


File: Main.java

import javax.ejb.EJB;
import javax.naming.InitialContext;

public class Main {

  public static void main(String[] a) throws Exception {

    EmployeeServiceRemote service = null;

    // Context compEnv = (Context) new InitialContext().lookup("java:comp/env");

    // service = (HelloService)new
    // InitialContext().lookup("java:comp/env/ejb/HelloService");
    service = (EmployeeServiceRemote) new InitialContext().lookup("EmployeeBean/remote");




File: jndi.properties

  Download:  EJB-EJBWithRemoteInterface.zip( 4,488 k)

27.5.Remote Local Interface
27.5.1.EJB With Remote Interface