// Ebean: Code example with Issues
public void updateEmployee(int empId, String name, long salary, Date hireDate){
try{
Ebean.beginTransaction();
Employee employee = Ebean.find(Employee.class, empId);
employee.setName(name);
employee.setSalary(salary);
employee.setHiredate(hireDate);
Ebean.commitTransaction();
}finally{
Ebean.endTransaction();
}
}
The extra Select Statement
The above code performs an additional query. For some this extra performance cost is acceptable.
However for people with big busy databases you probably don't want to have an additional query
for every update (or delete) performed like this. Your DBA may have words :)
No Optimistic Concurrency Checking
You may also note that Optimistic Concurrency Checking has been bypassed.
There is Optimistic Concurrency Checking between the query and
the update but not for the 'user think time'. The nasty thing about this is that any 'lost updates'
will occur 'silently' - and no one may notice for some time.
Refer Optimistic Concurrency Checking
General Rule: Stateless applications and Updates/Deletes
For me there is a general rule that for Stateless applications (where you don't have the original bean)
and you perform updates or deletes you need to think about these two issues.
ORM is not necessarily the best approach in this situation.
|