2

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...

psaw.mora
  • 868
  • 1
  • 7
  • 18

2 Answers2

5

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.

Dave Whittaker
  • 3,102
  • 13
  • 14
1

You have an access to the JDBC's java.sql.Connection (connection in Session), so if you really cannot use transaction / inTransaction, you can call rollback there.

With access to the connection, you can also execute arbitrary SQL requests and so change the database schema, but be mindful that your squeryl-using code has a static, compile time known schema.

Didier Dupont
  • 29,398
  • 7
  • 71
  • 90