Question

I created structure for separate business-logic of @Entities, I did @Entity like POJO and this extends in something like a BO contains business-logic and validations.

I think send my "BO" for CRUD but problem are when I want read return me @Entity object (I don´t know if I must create converter or something) but when I want create, update or delete return me error says "BO" is not know @Entity (I know this but I should some way to take father class).

Any idea?

UPDATE

entity class

@Entity

public class Employee {

protected String id;

protected String name;

protected float salary;

protected Employee() { }

public final String getId() {
    return id
}
public void setId(String id) {
    this.id = id;
}
public final String getName() {
    return name
}
public void setName(String name) {
    this.name = name;
}
public final float getSalary() {
    return salary
}
public void setSalary(float salary) {
    this.salary = salary;
}

}

My BO:

public class EmployeeBO extends Employee{

public EmployeeBO(String id, String name, float salary) {
    setId(id);
    setName(name)
    setSalary(salary);
}
public  final void setSalary(float salary) {
    //bussines logic
}
public final void setName(String name) {
    //bussines logic
}
public final void setId(String id) {
    //bussines logic
}

}

And then I work only EmployeeBO. For example em.remove(employeeBO)

Was it helpful?

Solution

Your business layer should operate on top of your data layer and be organized into logically connected groups. Something like this:

public class EmployeeInfoOperations {

    public final void updateName(Employee employee, String newName) {
        //bussines logic: trigger name update on external systems?
    }
    public final void updateContactAddress(Employee employee, Address newAddress) {

    }
}

public class EmployeeAccounting {

    public  final void changeSalary(Employee employee,float newSalary) {

    }

    public final void giveBonus(Employee employee, bigdecimal bonusAmount) {
    }
}

Your bussiness operation classes don't even have to be centric around one entity type. Think about group of business operations, small enough to become one class, and use any entity types as arguments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top