• 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

JPA merge() is removing duplicate row instead of throwing constraint violation

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I currently have 2 classes : AgencyDetail and AgencyBlockedDayDetail defines as follows:



Note that variables startDate and endDate are declared in superclass CalendarEvent.

And the AgencyDetail class is:



The problem is when I have two AgencyBlockedDayDetail objects i.e.
bdd1 with a reference to an AgencyDetail object agency01 and
bdd2 with a reference to an AgencyDetail object agency02.

I have the scenario where I update the AgencyDetail on bdd2 as follows:

At this point bdd1 and bdd2 are logically equivalent according to my equals() and hashCode() methods. However after the merge() runs in the update method of the service layer, bdd2 is removed/deleted completely. I would prefer a constraint violation exception to be thrown since attempting to save this would violate the unique constraint I have specified (i.e. startDate, endDate, agencyDetail).

Is this the correct behaviour? Can I get it to throw the constraint violation exception rather than just merging? This would be preferable as the user may have accidently entered in the wrong dates or agency detail.

An example of my jUnit test that fails is as follows:

reply
    Bookmark Topic Watch Topic
  • New Topic