JPA entities in custom WebSession

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

JPA entities in custom WebSession

Frank Henningsen
This post has NOT been accepted by the mailing list yet.
I use my own WebSession implementation. This session contains an JPA entity (the logged-in user). I handle transactions on my own using a RequestCycleListener that begins the transaction in #onBeginRequest and commits the transaction and closes the entity manager in #onEndRequest.

Now to use the user entity that is referenced in the session during the transaction I would need to merge it for each request. But that seems a bit fragile to me: Next time I add a new entity to the session and I will forget to merge it.

Is there any best practice to handle JPA entities in WebSessions? Without using Spring or CDI?