Search code examples
scalasqueryl

How To:Transaction Rollback in squeryl


Can anybody please tell me how to handle a transaction rollback in squeryl explicitly?

And also how can we add or remove columns in squeryl dynamically?

Thanx...


Solution

  • Just to elaborate a bit on the response from @didierd. There is one Session/Connection bound to each transaction. You can access the current Session, and thereby the Connection with code like:

    Session.currentSession.connection
    

    Or, if you're not sure if you're within a transaction

    Session.currentSessionOption map {_.connection}
    

    If you do roll back the transaction this way it will be your responsibility to start a new one or make sure there is no further use of the connection, so use with care.