geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lasantha Ranaweera <lasan...@opensource.lk>
Subject Re: J2EE EJB design question
Date Mon, 02 Oct 2006 11:08:24 GMT
Hi Mattias,

Following is a better way to this thing.

1. Define a Session Bean which act as a Facade.
Say EmployeeServiceBean class with changeEmplpyeeSalary(int id, double 
percentage)
2. That method will be some thing like this.
changeSalary(int id, double percentage) {

//EJB Home Find ---
Employee emp = empHome.findByPrimaryKey(id);
emp.setSalaray(emp.getSalary()*pesentage);
}

In this kind of solution Entity Bean will take care of database saving 
part. It will automatically save at the end of setSalary() method (This 
will be handled in the end of a Transaction).

Regards,
Lasantha Ranaweera

Mattias Malmgren wrote:
> Hi
>
> Perhaps out of topic, but anyway, this is my question:
>
> As far as I can understatnd, an enity EJB can not have business 
> methods, just getter/setter methods for the, in the database 
> underlaying fileds in a table, along with the methods in the 
> EntityBean interface.
>
> Say I have an Employee object like this:
>
> class Employee {
> int id;
> String name;
> double salary;
>
> void changeSalary(double percentage) {
> salary = salary + (salary * (precentage / 100));
> }
> void save() {
> myDatabase.saveEmployee(this);
> }
> }
>
> Using EJB what do I do? In an enity EJB I can't have the changeSalary 
> method? If I have it as a Session Bean, I can't have presistance and 
> save the objects data? What is the design soulotion?
>
> Best regards // Mattias
>
>


Mime
View raw message