Skip to content

Latest commit

 

History

History
48 lines (34 loc) · 2.02 KB

sessions-and-tx.textile

File metadata and controls

48 lines (34 loc) · 2.02 KB
layout title
manual
Sessions and Transactions

Bootstrap with org.squeryl.SessionFactory

SessionFactory.concreteFactory must be initialized before Squeryl transactions can be invoked :

After the initialization of SessionFactory.concreteFactory, the transaction and inTransaction block functions (call by names) become available :

The ‘transaction’ function binds the session to the current thread for the duration
of the block, so any method called directly and undirectly from the block
will be in the context of the transaction.

Distinction between transaction and inTransaction

  • ‘transacton’ causes a new transaction to begin and commit after the block’s execution, or rollback if an exception occurs. Invoking a transaction always cause a new one to be created, even if called in the context of an existing transaction.
  • ‘inTransaction’ will create a new transaction if none is in progress and commit it upon completion or rollback on exceptions. If a transaction already exists, it has no effect, the block will execute in the context of the existing transaction. The commit/rollback is handled in this case by the parent transaction block.