4
votes

I've got a SessionScoped managed bean (UserInfoController) with an Injected Stateless Session Bean (UserInfoService).

UserInfoController calls the UserInfoService to update UserInfo records. The UserInfoService loads the appropriate UserInfo record, modifies it and finally calls em.flush();

When the managed bean UserInfoController is annotated with the CDI annotation (javax.enterprise.context.SessionScoped), the user record is not updated unless the stateless bean's entity manager is annotated with PersistenceContextType.EXTENDED.

When the managed bean is annotated with the JSF annotation (javax.faces.bean.SessionScoped) the record updates successfully when using PersistenceContextType.TRANSACTION.

Can anyone explain this behavior? Shouldn't the transaction boundary be limited to the Stateless Bean regardless of whether the caller is a JSF or CDI SessionScoped managed bean? (TransactionAttributeType is not defined: it should default to REQUIRED)

Any info would be greatly appreciated! Thanks! Ben

1
I think I've got it, but you could add code please? - LightGuard
The bean in which you inject should not matter in this case. The only thing that can influence this is if the caller has already started a JTA transaction or not. You need to post your code for someone here to determine if this happens or not. - Mike Braun

1 Answers

1
votes

PersistenceContext type depends on the EJB session bean, not the backing bean like what is explained in this link What is the difference between Transaction-scoped Persistence context and Extended Persistence context?

I'm using @Named CDI beans with default PersistenceContext type (TRANSACTION) in my case and records update successfully when I'm using javax.enterprise.context.SessionScoped