So finally, I have started the real migration. Thanks to this exercise with the test case first and some help from you guys, the migration is going smoothly so far.
This is an anti-pattern and we'll get rid of it but as a first step during migration I want to make it work first. What is the correct way to handle this case? I come up with this solution:
public class TransactionFilter implements Filter {
@Inject
private TransactionalWork work;
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
work.run(request, response, chain);
}
@ApplicationScoped
public static class TransactionalWork {
@Transactional
public void run(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
chain.doFilter(request, response);
}
}
}
And registered it on a path where we need transaction to avoid lazy initialization error from hibernate. It's working as expected so far. Any suggestion?