How we use a smooth transaction at the service level to create a transaction system

at my service level, I want to insert a transaction, if inserted, than all three rows are inserted into the database.

Service level

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

my dao level

 def insert(userRow: UsersRow) = DB.withTransaction { implicit session => user += userRow } 
+1
scala playframework slick
source share
1 answer

change the insertion method to

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

The session will be distributed, and all inserts will use the same session. If the session uses a transaction of your example, this will be done in the same transaction.

+1
source share

All Articles