I have built a custom Java API with a call to update an existing record. It does a find for the record, finds it, updates the field, then does a save. Unfortunately the save generates a new record instead of updating the existing. I’ve made sure the class has a full set of getters/setters and the default constructor.
Here’s my log output.
searching for? CA87360A-06CF-466D-FFCE-306C3BDE5400
records found 3
existing record? Optional[DeviceUsage{Id=‘3D839E06-C647-76EC-FF35-F6939C33CC00’, DeviceId=‘0D4A9057-B9D8-95AA-FF36-8229B0339000’, MobileDeviceId=‘CA87360A-06CF-466D-FFCE-306C3BDE5400’, UsageCount=4}]
Trying to update existing Device Usage DeviceUsage{Id=‘3D839E06-C647-76EC-FF35-F6939C33CC00’, DeviceId=‘0D4A9057-B9D8-95AA-FF36-8229B0339000’, MobileDeviceId=‘CA87360A-06CF-466D-FFCE-306C3BDE5400’, UsageCount=4}
Trying to update existing Device Usage DeviceUsage{Id=‘3D839E06-C647-76EC-FF35-F6939C33CC00’, DeviceId=‘0D4A9057-B9D8-95AA-FF36-8229B0339000’, MobileDeviceId=‘CA87360A-06CF-466D-FFCE-306C3BDE5400’, UsageCount=5}
Trying to save Device Usage DeviceUsage{Id=‘3D839E06-C647-76EC-FF35-F6939C33CC00’, DeviceId=‘0D4A9057-B9D8-95AA-FF36-8229B0339000’, MobileDeviceId=‘CA87360A-06CF-466D-FFCE-306C3BDE5400’, UsageCount=5}
Device Saved:DeviceUsage{Id=‘3D839E06-C647-76EC-FF35-F6939C33CC00’, DeviceId=‘0D4A9057-B9D8-95AA-FF36-8229B0339000’, MobileDeviceId=‘CA87360A-06CF-466D-FFCE-306C3BDE5400’, UsageCount=5}
It does a search by criteria, finds 3 that match, then filters for the single record that matches exactly. After that the log shows the record, with a “UsageCount = 4”, increments the count to 5, then attempts to save it back to the database, and even says it saved successfully. However, instead of updating, it creates a new one (see the DB screenshot. 2nd highlighted row should’ve update instead of 1st highlighted row being generated)
Thanks, Mark