what is the best practice Business validation in transaction scope or out of tx scope for EJB ?
-------------------------------------------------Validation in Not Tx scope ------------------------------------------------------------------
@Stateless
public class CustomerBean implements CustomerBeanLocal {
private EntityManager em;
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void isValidCustomer(Customer customer) {
// perform some validation for customer related db query
if (customer != null) {
isCustomerActive(customer);
}
createOrder(customer);
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void createOrder(Customer customer) {
em.persist(customer);
}
}
===========================Validation in Tx scope =============================================
@Stateless
public class CustomerBean implements CustomerBeanLocal {
private EntityManager em;
@TransactionAttribute(TransactionAttributeType.REQUIRED)
private void createOrder(Customer customer) {
// perform some validation for customer related
if (customer != null) {
isCustomerActive(customer);
}
em.persist(customer);
}
}
===========================================
Which one is best and why best ?????????