Your transactional proxy will create a transaction
for each method invocation of the target object. You are calling two methods of your DAO, therefore each of them will properly be executed
in its own transaction. The same happens when you use an SLSB: Each method invocation will be executed in its own transaction.
If you want to execute multiple method calls within the same transaction, you need to demarcate that. A typical way of doing this is to create a transactional proxy for your high-level business service instead of for your DAO. Each business service method will then get executed in its own transaction, being able to call as many DAO methods in it as needed.
You can also demarcate such high-level transactions programmatically, via TransactionTemplate (or PlatformTransactionManager directly):
Code:
ctx = new FileSystemXmlApplicationContext("applicationContext-hibernate.xml");
PlatformTransactioManager tm = (PlatformTransactionManager) ctx.getBean("transactionManager");
final CategoryDAO bean = (CategoryDAO) (ctx.getBean("targetService"));
TransactionTemplate tt = new TransactionTemplate(tm);
tt.execute(new TransactionCallbackWithoutResult() {
public void doInTransactionWithoutResult(TransactionStatus status) {
bean.saveCategory(new Category( "new category"));
bean.getCategory(new long(1000));
}
});
Juergen