Hi Ludovic! One possible solution is the locking as you already explained. Another one which worked well for me is to wrap JSF sendRedirect and close the EM in there. Would need to think how we can make this solution more broad and generally available. A third solution would theoretically be to ‚postpone‘ the redirect until the end of the request.
This is surely an area where we could make it a LOT easier for Seam2 users (and other CRUD style projects) to get their apps ported over to CDI. So any ideas, objections and tricks are welcome :) LieGrue, strub > Am 19.04.2015 um 21:02 schrieb Ludovic Pénet <[email protected]>: > > Well, I experienced very often this kind of bug even with a simple filter > implementing open view scope pattern. > > My (violent but efficient) fix was to lock on the hibernate session before > passing the request to the next layer. > > So, I take Mark warning very seriously. > > And, Mark, is there something preventing such undesired behaviour if I stick > with the proposal on DS JPA module page with a production of a > @ViewAccessScoped EM ? Can I take for granted that only one thread at a time > will be allowed or would I better backpedal immediatly to @RequestScoped (or > toy with a filter to both lock and provide a ready for injection EM) ? > > Ludovic > > Le 19 avril 2015 17:24:08 UTC+02:00, Mark Struberg <[email protected]> a > écrit : >> Hi Dennis! >> >> >>> Have you *ever* hit this situation? >> Yes, under heavy load it happens pretty often actually (I’m talking >> about multi-million request/day public internet apps). It also depends >> a bit on the JPA container you use. From the pure spec it is forbitten >> to touch the EntityManager in parallel threads and also to touch >> managed (‚attached’) entities in parallel threads. What JPA container >> are you using? >> >> >>> Also, who programs a „sendRedirect" in the middle of a method that >> then performs database access ..? >> >> You don’t need to do database access even. It is enough that the >> entitymanager is not closed as per the spec. >> >> >>> Even so, this is pure theory, the chance are so tiny this happens… >> Then I had bad luck - quite often ;) >> >> >>> And If you think this *may* happen within one conversation, then >> change the way redirects are send, or the way database is accessed in >> parallel in Ajax requests. not the way EM is used IMHO >> >> That might be a solution. Or force the EM to get closed before the >> redirect. >> >>> Also your remark on „unfinished thread" is valid for ANY >> components/resources held in ConversationScope, not just the EM, true? >> >> Yes, but most components have no problems with getting accessed in >> parallel. For managed Entities and EntityManagers it’s explicitly >> forbidden by the JPA spec. >> >> LieGrue, >> strub > > -- > Envoyé de mon téléphone Android avec K-9 Mail. Excusez la brièveté. > | > | AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT. > |
