Reputation: 35
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
}
Upvotes: 1
Views: 534
Reputation: 11270
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.
Upvotes: 1