@Transactional
public Object[] cityAgents(Province province, Set<ProvinceAgents>
agents,Set<ProvinceAgentDetails> details) {
province.setCityagents(agents);
for(ProvinceAgents agent : agents){
for(ProvinceAgentDetails detail :details){
agent.setCityagentdetails(detail);
detail.setAgent(agent);
}
return cityDAO.saveBoth(province, agent);
}
return null;
}
}
This method is from my Service with @transactional annotation.
I want to set detail for each agent. However , its setting all the details for only one agent.
Is there any way out , I can make my inner for-each loop to work for 1st user only and other time when outer loop iterates , my inner loop put details corresponding to 2nd user
Thanks for help appreciated
You are returning too early. Move this return to the bottom:
return cityDAO.saveBoth(province, agent);
And delete the
return null;
Unless you don't want it to return anything, at which point just change the first line to
cityDAO.saveBoth(province, agent);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.