Imagine this code:
foo() {
Connection conn = ...;
}
foo()called from a method that has an annotation @Transactional. How to get current JDBC connection? Please note: it foo()is located in a bean (therefore, it can have fields @Autowired), but foo()cannot have parameters (therefore, I cannot pass the connection from somewhere).
[EDIT] I am using jOOQ, which needs either a data source or a connection. My problem: I do not know which transaction manager is configured. It could be anything; A Java EE based on a DataSource is something that gets a data source through JNDI. My code is not an application, it is a library. I need to learn what others have put on my plate. At the same time, I cannot request a Hibernate factory session, because an application using me may not use Hibernate.
But I know that other code, like Spring Hibernate integration, can somehow get the current connection from the transaction manager. I mean, Hibernate does not support Spring Transaction Manager, so the glue should adapt the Spring API to what Hibernate expects. I need to do the same, but I could not understand how it works.
[EDIT2] I know that there is an active transaction (that is, Spring has a Connection instance somewhere or at least a transaction manager that can create it), but my method is not @Transactional, I need to call the constructor, which takes java.sql.Connectionas a parameter. What should I do?
source
share