score:0

Accepted answer

OK, unless someone has a better idea, here's what I'm rolling with:

Since DAO to Entity is a 1-to-1 relationship, and ScalaQuery auto commits queries executed in a session block, performing multiple inserts on separate entities is not possible via my DAO implementation.

The workaround is to create a GenericDAO, one not tied to a particular entity, which provides transactional query functionality, with error handling extracted into parent trait

    def createMember(...): Boolean = {
      db.handle withSession { implicit ss: Session=>
        ss.withTransaction {
          val result = for{
            u <- safeInsert( UserMapper.insert(ubean) )(ss)
            ...
          }
          ...

At the controller layer the implementation becomes dao.createMember(...) which is quite nice, imo, transactional inserts using safe for comprehension, cool stuff.


Related Query

More Query from same tag