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.
Asked
Active
Viewed 1,910 times
1
-
2Generally 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? – fhossfel Aug 28 '17 at 16:36
-
Yes, it looks like a special requirement @fhossfel, we are using a temporary tables on the connection – Vinoth Rajendran Aug 29 '17 at 04:12
-
Why don't you clean the temporary tables on commit? At least with Oracle that is the default. – fhossfel Aug 29 '17 at 08:10
2 Answers
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.

M. Prokhorov
- 3,894
- 25
- 39

Imran
- 1,732
- 3
- 21
- 46
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.

jonathan.ihm
- 108
- 1
- 1
- 8