Java Reference
In-Depth Information
<persistence-unit name="chapter04PU"
transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>onlineRegDataSource</jta-data-source>
</persistence-unit>
</persistence>
After declaring a JTA transaction type persistence unit, the developer can either
leave the transaction management to the server (by default, the container considers
a method as a transaction) or take control and define the transaction boundaries pro-
grammatically.
The following code is an example of a container-managed transaction:
@Stateless
public class StudentServiceCMT {
@PersistenceContext
EntityManager em;
public void createStudent(){
Student student = new Student();
student.setBirthdate(new Date());
student.setDepartid("GI");
student.setId(""+ new Date().getTime());
student.setFirstname("CMT - FIRST NAME");
student.setLastname("CMT - Last name");
em.persist(student);
}
}
The following code is an example of bean-managed transaction:
Search WWH ::




Custom Search