Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA not usable with CDI scopes that are managed in HttpSession?

All CDI managed beans that belong to a scope that is ultimately bound to the HttpSession need to be serializable. Which means all attributes need to be serializable. EntityManager is not though this seems to be considered a bug (here and here (I don't know why it's closed.)).

This means if you want to adhere to the spec you cannot use JPA from CDI scopes like Session or Conversation.

Seems Java EE is close to unusable or what?

like image 211
user953217 Avatar asked Jul 04 '26 12:07

user953217


1 Answers

you're right : EntityManager is not serializable, but do you think CDI EG didn't notice that :-) ?

So when a CDI bean is Serialized (i.e. passivation of a SFSB) the EntityManager is considered as transient and is not. When then bean is unserialized the EntityManager is automatically re-injected in the Bean and so it works as it used to be.

The problem is when you use Extended Persistence Context in your Bean. Java EE spec doesn't support serialization of such bean. But framework like Seam 2 for Java EE 5 or CDI extension like Seam3 Persistence in Java EE 6 gives you possibilities to manage those special use cases.

like image 106
Antoine Sabot-Durand Avatar answered Jul 08 '26 18:07

Antoine Sabot-Durand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!