cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple Persistence Units AND one transaction

Former Member
0 Kudos

Hello,

I'm using JPA implementation for my EJB Project.

I have 2 persistence units and I'm using them in the same method.

I want to persist 2 object belonging each one to a different persistence unit

The 2 persistence units are related to different databases.

Everything is going fine and no exception is raised BUT only one object is persisted and the other one is not.

Have anyone had a similar problem before.

Any help will be appreciated.

Thanks in advance.

Edited by: ImaneA on Jan 18, 2011 9:29 AM

Accepted Solutions (0)

Answers (2)

Answers (2)

rolf_paulsen
Active Participant
0 Kudos

Hi,

are the data sources set up in NWA as XADataSources ?

Regards

Rolf

Former Member
0 Kudos

Hi,

In the SAP official documentation the following is stated:

Due to the specifics of the Dali JPA Tools project, we recommend that you define only one persistence unit within the persistence.xml file.

(http://help.sap.com/saphelp_nwce72/helpdata/en/48/f8238a550240aae10000000a421937/frameset.htm)

...which at first would mean that you should use two persistence.xml files (i.e. two separate projects (EJB, JPA, Web...)) for your two persistence units.

Regards,

Yordan

Former Member
0 Kudos

@Yordan :

First of all, thanks a lot for you answer.

At the end, I didn't use two EJB Projects :

1 - I used only one datasource( associated to one database ) in the persistence.xml

2 - I created a DBLink in SQL Server

3 - I created a synonym in the first database to get data from the second database.

And it works

But thanks for the answer, I may use you solution in my next project

@Rolf :

No, In NWA I've declared my datasources as normal datasources.

But Plz if you have docs that talks about XDataSources plz share them and thanks in advance.

Edited by: ImaneA on Jan 25, 2011 9:21 AM

rolf_paulsen
Active Participant
0 Kudos

Hi.

look e.g. at AFAIK this is required for distributed transactions/2 phase commit.

But when you can let the databases handle the 2PC you are safe.

Regards.

- Rolf

Former Member
0 Kudos

Thanks for your answer.

For now, my problem is solved by using a DBLink but I may use XDataSources in the future.

Imane.