Persist and save are different and they work differently. Check the hibernate/jpa docs for that. Differences are subtle but they are there... Basically persist refreshes the entity, save doesn't, so after the update with persist you get a fresh instance.
I suggest a read on how spring aop and tx management works.
psuedo code (servlet).
Code:
[tx-start]
dealer=dealerService.getDealers(request.getParamet er("companyCode"), request.getParameter("dealerNo"));
[tx-end]
[tx-start]
dealerService.mergeDealer(dealer);
[tx-end]
Set addrs=dealer.getAddrs(); ---> Does not work !
psuedo code (junit)
Code:
[tx-start]
public void testUpdateDealers() {
Mdl1 dealer= dealerService.getDealers("15", "414050");
dealer=dealerService.mergeDealer(dealer);
List addrList=new ArrayList(dealer.getAddrs().size());
// Do some updates for example :
for(Iterator i=dealer.getAddrs().iterator();i.hasNext()
{
Addrmst addr=(Addrmst) i.next();
addr.setLastUpdatedTimestamp(new Date());
}
dealerService.updateDealer(dealer); --> JUnit works with save and persist
}
[tx-end]
Do a search for open session in view, configure the filter, that way you have 1 hibernate session for the whole request, instead of multiple (for each tx).