Monday 4 May 2009

5-How to Develop Bean-Managed-Persistence Entity Beans

Here is my solution:
FILE:sTUDENThome
package bmpex;

import javax.ejb.*;
import java.util.Collection;
import java.rmi.RemoteException;

public interface StudentHome extends EJBHome
{
/* Create methods */
Student create(String studentId, String firstName, String lastName,
String address) throws CreateException, RemoteException;
/* Finder methods */
public Student findByPrimaryKey(String studentId)
throws FinderException, RemoteException;
public Collection findByLastName(String lastName)
throws FinderException, RemoteException;
/* Home methods */
public int getTotalNumberOfStudents() throws RemoteException;
}

FILE: Student.java
package bmpex;

import javax.ejb.EJBObject;
import java.rmi.RemoteException;

public interface Student extends EJBObject
{
public String getStudentId() throws RemoteException;
public String getFirstName() throws RemoteException;
public void setFirstName(String firstName) throws RemoteException;
public String getLastName() throws RemoteException;
public void setLastName(String lastName) throws RemoteException;
public String getAddress() throws RemoteException;
public void setAddress(String address) throws RemoteException;
}

FILE: StudentDetails.java
package bmpex;

public class StudentDetails
{
String id;
String firstName;
String lastName;
String address;
StudentDetails(String id, String firstName,
String lastName, String address)
{
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
}
public String getFirstName() {return firstName; }
public String getLastName() {return lastName;}
public String getAddress() {return address; }
}