Say we have the following code snippet:
@Entity
public class User {
@Id
private String name;
@OneToOne(cascade = CascadeType.ALL)
private Address address;
}
@Entity
public class Address {
@Id
private int id;
private String street;
}
@Stateless
public class UserLogicClass {
@PersistenceContext
private EntityManager entityManager;
public void logicOnUser(User user) {
if(logicOnAddress(user.getAddress()) {
otherLogicOnUser(user);
}
}
public boolean logicOnAddress(Address address) {
entityManager.find(address);
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void otherLogicOnUser
entityManager.find(user);
}
}
The question is based on comments from the latter method; I'm curious what happens in both the Spring case and the EJB case. Suppose Spring is configured with JTA transactions, and any method called from this class will start a new transaction, as in EJB.
source
share