Spring, BasicDataSource and OpenJPA

So you want to use Spring with commons BasicDataSource and OpenJPA? There is an interesting gotcha.

Let’s start with just the DriverManager DataSource for comparison. In your spring context you define the datasource like this:

Then your EntityManager Factory:

Here META-INF/persistence.xml is almost empty because all the properties are specified here in Spring. See the Spring docs for more info.

The trouble starts when you change your datasource to this:

It “should” just work. No such luck. To make a long story short you have to change the openjpa properties.

Here is the combination that works.

You have to gang up four properties into openjpa.ConnectionProperties. Intuitive huh?

One Reply to “Spring, BasicDataSource and OpenJPA”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.