问题
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