|
[Next to the 3rd floor]
Suddenly found a more serious problem: the original poster's code is a bit illogical.
If you can successfully load() before, the record must exist. Then it must be update, why use saveOrUpdate() again? In saveOrUpdate(), you will press the main key to check once, the host, you have plunged yourself into a quagmire...
If you want to saveOrUpdate(), it means that the record you want to insert may or may not exist. Then the previous query is not only meaningless, but it will definitely bring an exception: if you use load(), you will set ObjectNotFoundException when the record does not exist. If you use get() and return null when the record does not exist, then a NullPointerException will follow
So, the supplement to the solution:
[b] If you want to saveOrUpdate(), you should remove the previous query, directly new Consumpatch() and assign values to its attributes, and then saveOrUpdate(). [/b] |
|