I want to select an entity with it’s children (join) after having merged (updated) the same entity within the same service (transaction). I know that merge return the object you updated but this object has the data which has been updated, not all the entity with the data of the database. Additionally, If after merging I execute an select trying to get the entity with all it’s children, it return’s the object updated only with the data updated (the rest of fields and children entities are null).
is there any way to resolve it? It’s mandatory to execute everything in the same transaction because the service have a lot of database operations that must be executed correctly before committing.
Thanks.
Regards.
It all depends on how you have structured your code. It would help if you can provide more information/code for what you are trying to achieve.
From your description, check, if you have set the cascade option properly between the entity and its children. You can set the cascade for Merge operation, which should refresh the children also. (Note: This would work only if any of the children were fetched before merge operation in case of lazy loading).
And for your second question, again it depends on how you have structured your code, and the way you are fetching data from db.
But, ideally, all the database operations related to one request/unit of work should be handled inside one transaction.