Created
February 2, 2012 00:44
-
-
Save odwrotnie/1720468 to your computer and use it in GitHub Desktop.
JPA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.persistence._ | |
object JPA { | |
val unit = "jpa" | |
val emf = Persistence.createEntityManagerFactory(unit) | |
def t[R](f: EntityManager => R) = { | |
val em = emf.createEntityManager | |
val transaction = em.getTransaction | |
transaction.begin | |
// Before | |
val res = f(em) | |
// After | |
transaction.commit | |
em.close | |
res | |
} | |
def em[R](f: EntityManager => R) = { | |
val em = emf.createEntityManager | |
// Before | |
val res = f(em) | |
// After | |
em.close | |
res | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment