how we use slick transaction on service layer for making a transaction System

喜你入骨 提交于 2019-12-11 11:36:43

问题


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:


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.



来源:https://stackoverflow.com/questions/28398482/how-we-use-slick-transaction-on-service-layer-for-making-a-transaction-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!