Java Reference
In-Depth Information
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class StudentServiceBMT {
@PersistenceContext
EntityManager em;
@Resource
UserTransaction userTx;
public void createStudent() throws Exception {
try {
userTx.begin();//begin transaction
Student student = new Student();
student.setBirthdate(new Date());
student.setDepartid("GI");
student.setId(""+ new Date().getTime());
student.setFirstname("BMT - FIRST NAME");
student.setLastname("BMT - Last name");
em.persist(student);
userTx.commit(); // commit transaction
} catch (Exception ex) {
userTx.rollback();//rollback transaction
throw ex;
}
}
}
Innovations introduced by JTA 1.2
Unlike the JPA Specification, JTA has known only a few improvements that can be
summarized in the following lines. First we have the addition of two new annotations.
The first is javax.transaction.Transactional , which provides the possibility
to demarcate transactions declaratively on CDI-managed beans or classes defined
as managed beans by the Java EE Specification. The second annotation added is
Search WWH ::




Custom Search