Stateful EJB with extended persistence context to handle user session

I use a CDI bean session to store information related to the user (his user bean, credentials, etc.). I have a save method every time the user changes his information (e.g. email, password, etc.). However, for this I could have a bean session with an extended persistence context. If I do, his custom object will be managed during his session, and changes to his email, etc. Will be synchronized without re-creating persistence contexts, etc. Is that a good idea? Should I have an extended persistence context open for so long? Does this also block user changes for external beans on the right? What should I do if I have an administrator trying to make changes to this user (this can happen).

+3
source share
2 answers

There are several side effects that you should beware of.

First of all, the extended persistence context that you use to store this user-defined object should not be used for others, since it automatically caches everything as it relates (L1 cache).

If you need to use this permanently connected user object in some other operation related to some other persistence context, you need to get a new instance instead of using the instance in the session area.

. , . , , - , "". , JPA. , , .

, . , , . , , , , .

, stateful beans CDI (, , , , , HTTP- ) . CDI , , .

+5

Java EE 6, :

  • "" (sfsb),
  • "" EM
  • "dbproducer" EM .
  • (, loadEntity() )
  • (, saveEntity() )

, :

  • ( , - - ).
  • ( ) , , persistence db, .
  • , - (, ), a OptimisticLockingException

charme, : -)

- EM - * * , , EJB .

, EM ( , ). Seam 3, EM , Seam 3, @Unwraps (Solder) @Produces , .

+5

All Articles