The problem with LOCK is that I have to lock the owner of the instance, instead of the insteance itself, kindof weird and difficult to make it consistent..
michal wrote:
Let me cite "Hibernate in Action" book here:
Quote:
Why can’t Hibernate open a new connection (or session) if it has to lazy-load
associations? First, we think it’s a better solution to fully initialize all
required objects for a specific use case using eager fetching (this
approach is less vulnerable to the n+1 selects problem). Furthermore,
opening new database connections (and ad hoc database transactions!)
implicitly and transparently to the developer exposes the application to
transaction isolation issues. When do you close the session and end the
ad hoc transaction—after each lazy association is loaded? We strongly
prefer transactions to be clearly and explicitly demarcated by the application
developer. If you want to enable lazy fetching for a detached
instance, you can use lock() to attach it to a new session.