Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jack Bush
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 553
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jack Bush
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic