Often we have to use some of the methods which don’t return anything useful. If I invoke saveOrUpdate() in hibernate , I don’t know whether it has been performed successfully .
I use a implementation like this (which I think is a bit awkward) :
public int saveOrUpdateA(A a) {
int resultFlag = 0 ;
try {
// obtaining session is omitted
session.saveOrUpdate(a);
resultFlag = 1 ;
} catch (Exception e) {
e.printStackTrace();
}
return resultFlag ;
}
How do you do this ? Any good idea ?
Exception should be caught in DAO layer or Service Layer ?
The lack of an exception is a success indicator.
If you truly want the indicator, I’d go for a boolean return.
Your application will still have to check the return status and handle it appropriately, which is not a whole lot different than handling the potential exception thrown by session.saveOrUpdate().