OpenJPA does not provide its own JDBC connection pooling, as this should already be supplied to applications running in a Java EE application server in container managed mode. For Java SE or applications running in application managed mode, the OpenJPA aggregate openjpa-all.jar
artifact and the binary assembly contains copies of Apache Commons DBCP, which provides a robust connection pooling implementation.
The JDBC DataSource configuration options that we will need to modify in order to use Apache Commons DBCP for connection pooling are:
connectionDriverName="org.apache.commons.dbcp.BasicDataSource" connectionProperties="DriverClassName=<prior connectionDriverName>, ..."
Additional Commons DBCP arguments can be provided in the connectionProperties value, such as:
MaxTotal=10,MaxIdle=5,MinIdle=2,MaxWait=60000
Please visit the Commons DBCP website for the entire list of configuration options and explanations.
Example 14.11. Using Commons DBCP with Apache Derby
<property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/> <property name="openjpa.ConnectionProperties" value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver, Url=jdbc:derby://localhost:1527/openjpa, Username=uid, Password=pwd"/>Notice that we supplied Username and Password settings, which are required by Commons DBCP for connecting to a database over the network, but can be dummy values if database security is not enabled.