Sharing a single datasource between multiple persistence units with TomEE and OpenEJB


In JavaEE a datasource generally means a pool. So if you have two persistence units using the same physical datasource it can be very interesting to be able to use the same pool (easier to configure the pool size for instance).

Was not as easy as it in TomEE and OpenEJB. That’s why we added an attribute to our resources: aliases.

Now you are able to say that a resource has some aliases in both XML and properties configuration formats.

Here some little samples:

  • in xml
<Resource id="datasource1" aliases="datasource2,datasource3" type="DataSource">
    <!-- config as usual -->
</Resource>
  • and in properties
datasource1 = new://Resource?type=DataSource&amp;aliases=datasource2,datasource3

This attribute is considered as the id one so it can be use in persistence.xml for [non-]jta-datasource, to lookup the datasource…

Advertisement

1 thought on “Sharing a single datasource between multiple persistence units with TomEE and OpenEJB

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s