18

If connection pooling is not defined in the persistence.xml for eclipse link, what is the default behavior?

Will it open and close a JDBC connection for every transaction? Will it create a connection pool with some defaults?

Donato Szilagyi
  • 4,279
  • 4
  • 36
  • 53
user1796571
  • 662
  • 2
  • 9
  • 21

4 Answers4

13

The default connection pooling for EclipseLink when not using a data source is a pool of min/max 32 connections, with an initial of 1 connections. So each transaction will use a pooled connection, and not connect/disconnect.

James
  • 17,965
  • 11
  • 91
  • 146
  • Are you saying the eclipselink supports connection pooling even if there is no reference for pooling in the persistence.xml file? – user1796571 Mar 01 '13 at 21:05
  • Yes, that is the default (pool of 32 connections) – James Mar 04 '13 at 16:13
  • 1
    And here are the configuration properties: http://eclipse.org/eclipselink/documentation/2.4/jpa/extensions/p_connection_pool.htm – eskatos Oct 06 '13 at 08:51
  • I don't understand this. I have not configured anything. If I start a lot of transactions in a very short amount of time, netstation shows me the same lot of TCP connections in TIME_WAIT state. Shouldn't it, If I assume you are right, be limited to a total of 32 connections here?? – col.panic Nov 23 '16 at 10:59
7

If you use an application server (Java EE) and container managed persistence, then you need to set up the connection pooling in the administration console of the application server, and don't need to set the pooling properties in the persistence.xml, e.g.:

<persistence-unit name="myPU" transaction-type="JTA">
  <jta-data-source>jdbc_my_DataSource</jta-data-source>
  <exclude-unlisted-classes>false</exclude-unlisted-classes>
  <shared-cache-mode>NONE</shared-cache-mode>
  <properties/>
</persistence-unit>

If you use EclipseLink without application server (Java SE), using application managed persistence, then if you don't configure pooling, Internal Connection Pooling will be used, e.g.:

<persistence-unit name="DemoPU" transaction-type="RESOURCE_LOCAL">
  <properties>
    <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
    <property name="javax.persistence.jdbc.user" value="myuser"/>
    <property name="javax.persistence.jdbc.password" value="mypassword"/>
    <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
  </properties>
</persistence-unit>
Donato Szilagyi
  • 4,279
  • 4
  • 36
  • 53
  • When you mean App server do you mean EE or SE? So when no connection pooling is defined its a connection for every tx? What about bean managed persistence using Spring/Tomcat? – user1796571 Feb 27 '13 at 20:21
  • 3
    Eclipselink still uses connection pools, it is just that it maintains the pool instead of using a datasource. Eclipselink internal pools are somewhat described here http://wiki.eclipse.org/Configuring_an_Internal_Connection_Pool_(ELUG) and jpa persistence properties to use are posted here http://wiki.eclipse.org/EclipseLink/Features/JPA#EntityManagerFactory_Properties – Chris Feb 27 '13 at 20:52
2
<property name="eclipselink.connection-pool.default.initial" value="1"/>
<property name="eclipselink.connection-pool.default.min" value="64"/>
<property name="eclipselink.connection-pool.default.max" value="64"/>
John Slegers
  • 45,213
  • 22
  • 199
  • 169
Armen Arzumanyan
  • 1,939
  • 3
  • 30
  • 56
1

Just wanted to provide the code source for James' answer above: You can see that a default connection pool is created in the constructors of ServerSession, using the init/min/max defaults defined in ConnectionPool, and optionally overridden/adjusted by the developer via properties in EntityManagerSetupImpl.

Glen Mazza
  • 748
  • 1
  • 6
  • 27