First to explain the context. I have backend Java (Spring/Hibernate) application that I access via JMS. I have client app (RESTfull) that I access via Url. I have a complex entity with more than one list (most of it are lazy) and this entity is composition of xy other entities.
Problem: Since I access it via URL, I create Java object in client app from URL parameters. I'm sending it to backend via JMS, but on the backEnd, I do not have Hibernate object, so I cant simple merge it.
I can go trough all that came from client like:
and repeat it for every composition entity, but I'm wondering if there is more elegant and "easy to maintain" way to update this entity with all changes.
I hope I explained it well. Thanks in advance!
From your description it seem the steps you follow are right. The first(get object) and last(update object) steps are inevitable. The only place where you can optimize is the checking/setting part. For that you can write a generalized method which accepts two objects and compares them for changes using Reflection. This way it can be reused again.
Here is a sample code using reflection. Change it to suit your need
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With