I'm trying to use guice-persist and I can't get it to work in a simple test case. This a generic request handler which is getting called from a dispatcher:
public abstract class TransactionAwareRequestHandler<T> extends SyncRequestHandler<T> {
@Transactional // Guice should make sure I get a transaction here
public final Object handleRequest(T request) {
return handleRequestWithTx(request);
}
public abstract Object handleRequestWithTx(T request);
}
My test handler is:
public static class TestHandler extends TransactionAwareRequestHandler {
@Override
public Object handleRequestWithTx(Object request) {
SessionFactory sessionFactory = injector.getProvider(SessionFactory.class).get();
assertTrue(sessionFactory.getCurrentSession().getTransaction().isActive()); // <<<--- Fails here!
return null;
}
}
Guice setup:
injector = Guice.createInjector(
new HibernatePersistModule()
);
This will add a bind interceptor for all classes and methods annotated with @Transactional
Test case:
@Test
public void shouldRunInTransaction() throws RequestHandlerException {
TestHandler handler = injector.getInstance(TestHandler.class);
// I'm not getting a proxy here! Why???
assertTrue("Expected proxy: " + handler.getClass(),
Proxy.isProxyClass(handler.getClass()));
handler.handleRequest(null);
}
Questions:
Why does this happen?
How can I debug this to find out why it's happening? Is there some way to add logging to the class/method matcher?