• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 553
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic