1

Currently, in my spring boot application has the capability to create connection object based on the DataSource given. In my manager layer, I have annotated with @Transactional. I need to have a new connection when entering methods in manager, even though we have an existing connection.

3
  • 2
    Generally speaking that would be a bad idea. Setting up a connection is an expensive operation. It is far more efficient to reuse a connection from the pool. Is there any special requirement why you can't reuse a connection? Commented Aug 28, 2017 at 16:36
  • Yes, it looks like a special requirement @fhossfel, we are using a temporary tables on the connection Commented Aug 29, 2017 at 4:12
  • Why don't you clean the temporary tables on commit? At least with Oracle that is the default. Commented Aug 29, 2017 at 8:10

2 Answers 2

1

Although it is not a good idea, disabling connection pooling should always return a new connection. How to completely disable Connection Pooling in Spring / Tomcat?

  • NOTE: This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call.

https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SimpleDriverDataSource.java

Sign up to request clarification or add additional context in comments.

Comments

0

I would not create new connections every time you call any sort of transactional method. This is expensive and very error-prone. You should be defining your data sources and then choosing which one you want to use.

Also, see Spring Boot Configure and Use Two DataSources

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.