java - entitymanager.merge() not behaving as I would expect (Creating a new record rather than updating) -
I could not find anything relevant. Based on whether I exported and / or updating bulk, whether the previous record is present based on the data read from the CSV exported or not.
Below are two records two databases, though I want to insert it and then update the same record.
If there is already a record in DB, then it works as expected, just updating the existing line
Before this, I was checking the tap And if only / else to add / update and everything worked well That setter had a lot of redundancy, so I changed it on it. I hope that it will always run the update, but in this event a record is not found, it will create a minimum viable distortion record which is updated later. The update works fine - the problem occurs when no pre-record exists, it creates an additional record
How and how this transaction is being done and why is it committed? I do not understand that the second merge creates a new entry when I pass an object to update it that already exists.
I can do all the things as I would like, but I should understand why it is not as I expected that I have lost a basic concept on merger and transaction?
Here my code is
Pathology Pathology = Gate Pathology (Unit Manager, SlideID, MDCLustring, Collate); If (zero == distortion) {entityManager.getTransaction (). Start (); Deformity = new pathology (); Pathology.setSlideId (slideId); Pathology.setCallType (CALLTYPE); Pathology.setCallBy (mdCallString); EntityManager.merge (deformity); Committed to entityManager.getTransaction (). } EntityManager.getTransaction (). Start (); Pathology.setSample (sample); Pathology.setSlides (slides); Pathology.setLocation (location); Pathology.setCallDx (sampleLevelDx); Pathology.setPatientDx (patientLevelDx); Pathology.setRadiologyReports (radiologyReports); Pathology.setModality (instrument); Pathology.setupdateedon (new date ()); String dtm = lineContainer.get (line container. (-) 1); DateFormat sdf = New Simple Format ("MM / dd / yyyy hh: mm a", Locale.US); Date callout = sdf.parse (dtm); Pathology.setCallDate (callDate); If (mdCallString == colbyCallString) {pathology.setRepresentativeSlideDigitized (currentSlide.get (3)); } EntityManager.merge (Pathology); Committed to entityManager.getTransaction (). Edit: So, everything works like I hope if I run Pathology pathology = gate pathology (unit manager, slide id, MDCLSTR) , Coltai); If (zero == distortion) {entityManager.getTransaction (). Start (); Deformity = new pathology (); Pathology.setSlideId (slideId); Pathology.setCallType (CALLTYPE); Pathology.setCallBy (mdCallString); EntityManager.merge (deformity); Committed to entityManager.getTransaction (). } Pathology = Gate Pathology (Unit Manager, SlideID, MDCelstring, Collate); EntityManager.getTransaction () start () .; Pathology.setSample (sample); Pathology.setSlides (slides); Pathology.setLocation (location); Pathology.setCallDx (sampleLevelDx); Pathology.setPatientDx (patientLevelDx); Pathology.setRadiologyReports (radiologyReports); Pathology.setModality (instrument); Pathology.setupdateedon (new date ()); String dtm = lineContainer.get (line container. (-) 1); DateFormat sdf = New Simple Format ("MM / dd / yyyy hh: mm a", Locale.US); Date callout = sdf.parse (dtm); Pathology.setCallDate (callDate); If (mdCallString == colbyCallString) {pathology.setRepresentativeSlideDigitized (currentSlide.get (3)); } EntityManager.merge (Pathology); Committed to entityManager.getTransaction ().
For the second time, the blank that is being examined after the blocks but I want to avoid the repetition. And about the basic question, what is the difference in pathology variables in two cases, which causes different results? In both cases, they mention the same current record in DB - so why someone moves towards one, while the other makes an update.
Thanks
Comments
Post a Comment