Play2 How to manage the transaction from the service layer instead of
action layer?
I am using Play2.11 Java with JPA2.0 with hibernate implementation.
to control the transaction by code instead of using @transactional like
below is the normal JPA code style, Is there any way to work like below at
Play? or how to use JPA.withtranaction() to do? I tried it, no idea how to
pass in the parameter, I am not familiar with functional code. thanks a
lot. Please give me some sample code based on below.
public void createActorB(final String email, final String psw) throws
Throwable {
EntityManager manager = JPA.em();
try {
EntityTransaction ex = manager.getTransaction();
this.dbActor.setEmail(email);
this.dbActor.setCredential(psw);
manager.persist(this.dbActor);
ex.commit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new ActorException(CODE.UNKNOWN, e);
} finally {
manager.close();
}
}
No comments:
Post a Comment