how we use slick transaction on service layer for

2019-07-29 14:59发布

in my service layer i want to insert transaction-ally if insert than all the three row are inserted in database !!

Service Layer is

def service(userRow, addressDao, contactDao) = DB.withTransaction { implicit session => 
    userDao.insert(userRow)
    addressDao.insert(addressRow)
    contactDao.insert(contactRow)
}

my dao layer is

def insert(userRow: UsersRow) = DB.withTransaction { implicit session =>
    user += userRow
}

1条回答
别忘想泡老子
2楼-- · 2019-07-29 15:17

change your insert method to

def insert(userRow:UsersRow)(implicit session: Session)={
    user+=userRow
}

The session will be propagated and all inserts use the same session. If the session is using a transaction as your example did, then it will be done in the same transaction.

查看更多
登录 后发表回答