aspose file tools*
The moose likes Object Relational Mapping and the fly likes How to ignore / merge duplicates in OneToMany when using multiple emf (ProJPA2) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to ignore / merge duplicates in OneToMany when using multiple emf (ProJPA2)" Watch "How to ignore / merge duplicates in OneToMany when using multiple emf (ProJPA2)" New topic
Author

How to ignore / merge duplicates in OneToMany when using multiple emf (ProJPA2)

Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235
Hi All,

I need your advice on how to ignore / merge duplicate records when persisting OneToMany unidirectional entity relationship tables that spanned over multiple entity manager factories. Below is the code snippet that I am referring to:


Desire output
----------------
John Doe – homePhone – 11111111
John Doe – workPhone – 22222222

However, below is the exception error encountered instead:

Yet this exception would not have occurred if all the persistent steps were carried out under the same Entity Manager Factory. However, the data that I am importing will have duplicates that will take place days, if not weeks later. The merging of Phone tables is working fine in general.

This issue appears to be a transactional Management one as opposed to a programming.

Thanks in advance,

Jack
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Your issue is you are creating your employeeService with emf1, then closing emf1, creating emf2, but still using the employeeService that still has emf1.

You need to create a new employeeService with emf2, or pass the em to the service operations, or don't create an emf2, just use emf1 and don't close it.


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235
Hi James,

You are absolutely right. This issue of “Attempting to execute an operation on a closed EntityManager” has been resolved after declaring a new employeeService2 that uses em2 & emf2.

Thanks a lot,

Jack
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to ignore / merge duplicates in OneToMany when using multiple emf (ProJPA2)