0

I am writing a JEE7 application that runs in WebSphere Liberty Profile 8.5.5. We are using JPA (which is implemented via Eclipselink in WLP).

I have multiple persistence units in the same 'persistence.xml' file. I also need to access two of those units in the same class.

I am getting a runtime error when I try to use the second EntityManager:

@PersistenceContext(unitName = "wwer-list")
private EntityManager entityManagerWwerList;
@PersistenceContext(unitName = "main-dashboard")
private EntityManager entityManagerMainDashboard;

E WTRN0062E: An illegal attempt to use multiple resources that have only one-phase capability has occurred within a global transaction.  

How do I get rid of this error?

Also, all of the tables I am using are only needed for reading. So how can I specify that I only want read-only access to JPA?

Westy
  • 707
  • 2
  • 10
  • 23
  • I got this from the error message. http://www-01.ibm.com/support/docview.wss?uid=swg21247192. What I understand is that you need distributed transactions to work across two persistent units. You might have to use something like Bitronix transaction manager to achieve that – kjsebastian Oct 25 '16 at 02:04
  • what does your persistence.xml look like? – Andy Guibert Oct 25 '16 at 02:07
  • jdbc/wwer-list com.ibm.youribm.services.expensesaggregator.ejb.dao.jpa.entity.WwerEntity jdbc/main-dashboard com.ibm.youribm.services.expensesaggregator.ejb.dao.jpa.entity.DashboardEntity ... – Westy Oct 25 '16 at 13:31
  • Sorry, I have never been able to get comments to format correctly. – Westy Oct 25 '16 at 13:37

2 Answers2

0

This issue is prompting because one of your datasource configured as (single phase commit) using ConnectionPoolDataSource and other is configured with XADataSource.

If you want to continue with the same datasource configuration, you will have to update your Server configuration to "Acccept Heuristic Hazard".

In the admin console, click the EAR, select the check box "Accept heuristic hazard". Re-start the server.

This link to enable the Last Participant Support may also help. http://www.ibm.com/support/knowledgecenter/SSAW57_7.0.0/com.ibm.websphere.nd.doc/info/ae/webui_pme/ui/ueac_laoextensionsettings.html

mhasan
  • 3,703
  • 1
  • 18
  • 37
  • Thanks. But I didn't configure XADataSource on purpose, I didn't set that anywhere. I only need to read the datasources, there will be no updating. – Westy Oct 25 '16 at 13:26
0

I can't tell for sure without your persistence.xml and server.xml configurations, but it looks like the <dataSource> elements backing your <persistence-unit> configurations are not XA capable.

By default, a <dataSource> should be a javax.sql.XADataSource (and therefore XA capable), however if you are using a JDBC driver that does not provide an XADataSource implementation, Liberty will pick a simpler DataSource implementation (i.e. javax.sql.ConnectionPoolDataSource or plain javax.sql.DataSource).

A global transaction is whenever you issue a UserTransaction.begin() and lasts until you issue a commit() or a rollback(). There are other ways that you can get into a global transaction too.

Since you want read-only access, converting your DataSources to XA would probably be overkill. Instead, try to eliminate the global transactions from the equation. If you can't eliminate the global transactions, you can specify XADataSource in your server.xml in the following way:

<dataSource type="javax.sql.XADataSource" ...>
    <jdbcDriver .../>
    <properties .../>
</dataSource>
Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
  • I'm not using global transactions, or at least not on purpose. This is purely a read-only service. So how do I get rid of global transactions? XA does sound like overkill, and it seems to me like it would slow things down too. – Westy Oct 25 '16 at 13:28