Hi, all!
I am no Hibernate expert (and I also come from C background, so I may even have some lingo problem) so please forgive me if I am asking trivial things. However, here is the problem...
we have an application which consists of two parts - Gui client, where DB persistence is to be implemented using Hibernate; also a few background processes which are written in Pro*C and can acess the same DB schema and modify data in the tables. So when Gui user runs a query (via Hibernate) and the results are displayed in a form, and then if user wants to modify data, before doing this we need to check that the data is not stale, that is that the record wasn't changed by some other process in the meanwhile.
I got it to work using method below, but this is only because I don't know any better way of doing this (table is param and it has four fields code, data, desc, userupdateable ).
Please help, is there a good way of comparing old and new records without going through all fields in a table... and generally, what's the best way of dealing with the issue, if anyone knows it?
public boolean equals(Object o){
if (this == o) return true;
if (!(o instanceof Param)) return false;
Param temp = (Param)o;
if (!pcode.equals(temp.getCode())) return false;
if (!pdata.equals(temp.getData())) return false;
if (!pdesc.equals(temp.getDesc())) return false;
if (!userUpdatable.equals(temp.getUserUpdatable())) return false;
return true;
}
then in the code you have something like
Param isParam = (Param)session.get(Param.class, lockKey, LockMode.UPGRADE);
if (!isParam.equals(oldIsParam)) {
lockMsg = DB_ERROR_TAG + isParam.getPcode() +
" has been modified by other source,<br>" + MSG_END ;
return false;
}
|