I've solved the problem now by using native sql:
First I try if I can lock the row:
Code:
session.createSQLQuery(
"select id from CLEANUP_TREE where id = :id for update nowait")
.setParameter( "id",id).list();
if I cannot lock it throws a GenericJDBCException that has nested another exception, whose message contains following text:
Code:
catch( GenericJDBCException e)
{
if( e.getCause().getMessage().contains("could not obtain lock on row in relation \"cleanup_tree\""))
{
return false;
}
else
{
throw e;
}
}
If I don't get the error, I just go on an get the thing via hibernate by id.
Especially the exception-thing is not beautful but it works at least for now.
But I will try the dialect-thing, perhaps I can use it on other places as well ...
Thanks