Reputation: 7859
Could someone give an example on where "persistence model" should be separated from "view model"? Why?
Persistence model:
@Entity
public class Employee {
@Id
private int id;
// Some other stuff
}
View model:
public class EmployeeModel {
private int id;
// Some other stuff
}
And where they should not be separated?
Upvotes: 1
Views: 162
Reputation: 691755
Where they should not be separated: when they match exactly, just as in your example.
Where they should be separated: when they don't match. For example, let's say you want to display a table containing, for each row:
That doesn't match with any persistence model entity, because in the persistence model, you'll have an Employee, with a ManyToOne association with a Department, and a ManyToMany association with Project. To load the data displayed in the table, you'll use an ad-hoc query which will load the required data from these three entities, using joins.
Upvotes: 4