Hello,
I need to have delayed constraint checks done, i.e. all constraints should be checked at commit time; this allows for temporarily inconsistent states while a transaction is in progress. I encountered two problems there so far:
1) Setting the constraints at the DB level. I tried to subclass Dialect (Oracle9Dialect) to add the known "deferrable initially deferred" clause at "not-null" or "unique", but the only hook there is getAddForeignKeyConstraintString(...) and it seems only few SQL is dispatched over the Dialect to that extent. For example, Table.sqlCreateString(...) and UniqueKey.sqlConstraintString(...) all use hardcoded SQL for uniqueness and not-null constraint creation. My solution was to patch these Hibernate classes directly ... .
2) Hibernate checks upon saving objects. When calling Session.save(...), Hibernate eagerly performs not-null constraint checks, etc. Is there a way to delay these to commit time, for the same reasons? I have a hard time understanding why it is done like this, consider a class where "a" is declared not-null:
then
Code:
obj.setA(null);
session.save(obj);
would fail, whereas:
Code:
session.save(obj);
obj.setA(null);
...
obj.setA(<something ok>)
tx.commit();
would pass.
I initially tried to delay the session.save(...) until very late in the transaction, but then you get other problems because domain code may already refer (or use them in queries, etc.) to persistent objects not yet known to Hibernate.
Any ideas? Anyone had similar stuff?
zup