Reputation: 1
I would like to understand about relationship between Stateless Sessionneans and DB Connections. Can someone give me information to the following questions based on the Scenaraios below? Thanks in advance.
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
// DEFAULT TRANSACTION ATTRIBUTE IS "REQUIRED"
public class StatelessSessionBeanA {
.....
@TransactionAttribute(TransactionAttributeType.NOT_REQUIRED)
public void methodA() {
methodB();
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
private void methodB() {
methodC();
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void methodC() {
.....
}
.....
}
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.NOT_REQUIRED) // THIS IS IMPORTANT HERE
public class StatelessSessionBeanB {
.....
@TransactionAttribute(TransactionAttributeType.NOT_REQUIRED)
public void methodA() {
methodB();
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
private void methodB() {
methodC();
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void methodC() {
.....
}
.....
}
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
// DEFAULT TRANSACTION ATTRIBUTE IS "REQUIRED"
public class StatelessSessionBeanC {
.....
@TransactionAttribute(TransactionAttributeType.NOT_REQUIRED)
public void methodA() {
methodB();
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
private void methodB() {
methodC();
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void methodC() {
.....
}
.....
}
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.NOT_REQUIRED) // THIS IS IMPORTANT HERE
public class StatelessSessionBeanD {
@Inject
private StatelessSessionBeanC beanC;
.....
@TransactionAttribute(TransactionAttributeType.NOT_REQUIRED)
public void methodA() {
methodB();
beanC.methodA();
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
private void methodB() {
methodC();
beanC.methodA();
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void methodC() {
.....
}
.....
}
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.NOT_REQUIRED) // THIS IS IMPORTANT HERE
public class StatelessSessionBeanE {
.....
@TransactionAttribute(TransactionAttributeType.NOT_REQUIRED)
public void methodA() {
methodB();
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
private void methodB() {
methodC();
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void methodC() {
.....
}
.....
}
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
// DEFAULT TRANSACTION ATTRIBUTE IS "REQUIRED"
public class StatelessSessionBeanF {
@Inject
private StatelessSessionBeanE beanE;
.....
@TransactionAttribute(TransactionAttributeType.NOT_REQUIRED)
public void methodA() {
methodB();
beanE.methodA();
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
private void methodB() {
methodC();
beanE.methodA();
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void methodC() {
.....
}
.....
}
Upvotes: -2
Views: 64
Reputation: 1027
I think you can figure this out by trying.
Do something like this:
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
// DEFAULT TRANSACTION ATTRIBUTE IS "REQUIRED"
public class StatelessSessionBeanA {
@Resource
TransactionSynchronizationRegistry tsRegistry;
private static final Logger LOGGER = Logger.Logger.getLogger(StatelessSessionBeanA.class.getName());
.....
private void logTransaction(){
Object tsKey = tsRegistry.getTransactionKey();
LOGGER.info("Transaction: " + tsKey == null ? "none" : tskey.toString());
}
@TransactionAttribute(TransactionAttributeType.NOT_REQUIRED)
public void methodA() {
logTransaction()
methodB();
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
private void methodB() {
logTransaction();
methodC();
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void methodC() {
logTransaction();
.....
}
.....
}
Do the same in the Bean where your Methods are called, then you can compare the log outputs.
Upvotes: 0