This is my plan, as of now:
1) XA database driver
2) Use <tx:jta-transaction-manager> in Spring
3) Inject a Spring TransactionTemplate into my EJB to wrap the delegation in a transaction; this will make one Hibernate Session available to my business objects ... but most importantly, I will be able to access the lazy-loaded properties that return from the service method
Example:
Code:
@Stateless
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class SampleEJB {
@Autowired
private SpringManagedService service;
@Autowired
private TransactionTemplate t;
public void foo() {
t.execute(new TransactionCallbackWithoutResult() {
@Override
doInTransactionWithoutResult(TransactionStatus status) {
MyEntity entity = service.foo();
entity.lazyCollection().iterator(); // access lazy properties; hibernate session still open
}
});
}
}
Two questions though:
A) Is #3 the right strategy? It's my version of OpenSessionInViewFilter for EJB
B) Should I set "hibernate.transaction.factory_class" and "hibernate.transaction.manager_lookup_class" in my SessionFactory properties? They are not set.
Thanks