This is a nasty misuse of the entity manager, so nasty it's almost sinful. As far as I am aware there should never be any need to manually clear it like that. I'm thinking one of those uses probably causes this error, and even if it doesn't I'm sure we're giving ourselves a performance hit by doing it so often.
One particularly egregious example is in MaterialListPriceRltnpBean.saveMaterialListPriceRltnp(). This method is a poster child for all-around shoddy programming (observe, for instance, that it can't decide whether it should begin or end the conversation), but in particular I'd like to show you this bull-in-a-china-shop snippet of code:
materialListPriceRltnpHome.refreshInstance(); materialListPriceRltnpHome.getEntityManager().clear(); materialListPriceRltnpHome.getEntityManager().find(MaterialListPriceRltnp.class, materialListPriceRltnpHome.getInstance().getMaterialPriceListPriceId()); materialSalesOrgRltnpHome.setInstance(materialListPriceRltnpHome.getInstance().getMaterialSalesOrgRltnp()); materialListPriceRltnpHome.refreshInstance();
If you look at that and mutter dejectedly, then you're not alone. This is the code of a man of little nuance, a man who really just wanted his entity but was clueless on how to properly go about getting it. We have code like this all over our application. It's really no wonder our house is falling down around us when we've built it with stinking, rotten wood. All through the app we have code that just sets out to do what it needs to do in the most direct way with no thought for the bigger picture, trampling everything in its path.
How much time have I wasted today alone because someone out there couldn't take the time to learn the proper way to use the tools they were given? Yet supposedly, hiring an army of junior contractors was the only way this project could have been built. Sure, we all make mistakes as we learn, and I do recognize that they feel the same pressure to JUST GET IT DONE OMG WE'RE RUNNING OUT OF TIME that I do and therefore cut corners, as I have done. I also recognize that we didn't give them the constant guidance they needed, but then again I don't think it would have been possible for the small number of us, even reviewing code ten hours a day for the last year, to quell the relentless influx of crap.
I firmly believe that we went about many things wrong on this project, and I know that some of them were the result of laziness or other faults on my part. I do not excuse myself for that. Yet I feel like a drop in the pond; without the good and bad I contributed, the project would still be ailing, because chief among our mistakes was the first one that was made. The model and methodology we chose are just fundamentally, seriously broken. In brazen defiance of common wisdom about the mythicality of the notorious man-month, we finally stopped the hollow overtures to "agile methodology" and openly abandoned it.
It's often said you can't make nine women have a baby in one month. Well, we skipped the nine women altogether and tried to convince 280 women to have a baby in one day. The baby that resulted doesn't seem to happy to have been saddled with the task of existence.
If I have to work any more weekends, I might just start to agree with him.