Working on this huge DAQ project made with GWT(mariaDB as db) , my main purpose is to replace some UI components and with them, their functionalities(for this case, users management , where you can add/edit/move around), to be straight , right now i am making islands on this project , where i detach from GWT ,and use for UI the framework Flutter(this framework is chose because later we want to have mobile compatibility and one single architecture). The communication so far between Flutter and the server is realized by API calls. I try to use with little to no modifications the functions that GWT use , i just take them and try to implement for my code. Now the problem is that , there is this one function that saves/edit users(yes it does both), and for some reasons when is triggered by an endpoint (@PostMapping , @Transactional) , behaves weirdly , what I mean is that when you try to change an user organization, this user has some area of interest on him (foreign key, eager fetch declared on sites variable inside class User), and when is moved to another organization , he will have he's sites moved with him also (sites has a foreign key to organization). When the function (saveAndmoveSites) that is made (with @Transactional) , to fetch the sites of the edited user and move them in the new organization, is called by saveUser function (that is called by flutter) for some reasons will not find anything at all, not a single site. But when all this is requested by GWT, everything is fine , will find and move all the sites of the user. Before the function saveAndMoveSites , there is this mapper where it will map the DTO received from request to user(using MappedFacade), and at sites(area of interest) field is empty (GWT sends empty field, flutter sends empty field). I see if this mapper is called by flutter before saveAndMoveSites makes the backend to clear the user sites and so will not find a single site when called by saveAndMoveSites, but if is called by GWT the mapper will clear the sites of user but then will find them somehow. I am very surprised by this weird behaviour, and i want to know how GWT (RPC) sessions and hibernate state management works , and why is behaving this function differently in Flutter.
At the beginning of the function, made this debug print to see exactly the DTO received , to see the differences between what i send from flutter and what is send by GWT. I can say matches 1:1, not a single thing different from one to another.
To fix this issue , i made a boolean variable that will check if the function is called by flutter, if so , will not call the mapper before saveAndMoveSites, but will call after that function. And everything so far is working as intended.
1 Answer 1
Your REST path maps an empty sites
collection onto a managed entity, Hibernate marks it dirty, and auto-flushes those deletes before your move query — so no sites are found. GWT’s path sidesteps the timing in some way, but it’s incidental. The durable fix is to never map sites
from the DTO for this endpoint and/or move sites via a bulk update before any mapping. That removes the timing hazard and makes both GWT and Flutter behave identically.
If you want, share your entity mappings (User
, Site
) and the mapper config you use (MapStruct/Orika/ModelMapper), and I’ll tailor the exact snippet to your stack.