Advertisement
Guest User

Untitled

a guest
Nov 9th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.81 KB | None | 0 0
  1. var session = appComponent.sessionFactory.openSession()
  2.     var transaction: Transaction? = null
  3.  
  4.     try {
  5.         transaction = session.beginTransaction()
  6.         session.get(MailPatternEntity::class.java, 1)
  7.         transaction.commit()
  8.     } catch (exception: RuntimeException) {
  9.         transaction?.rollback()
  10.         exception.printStackTrace()
  11.     } finally {
  12.         session.close()
  13.     }
  14.  
  15.     session = appComponent.sessionFactory.openSession()
  16.  
  17.     try {
  18.         transaction = session.beginTransaction()
  19.         val entity = MailPatternEntity(1, htmlText = "some text")
  20.         session.saveOrUpdate(entity)
  21.         transaction.commit()
  22.     } catch (exception: RuntimeException) {
  23.         transaction?.rollback()
  24.         exception.printStackTrace()
  25.     } finally {
  26.         session.close()
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement