[jboss-user] [JBoss Seam] - Re: When to use @PersistenceContext vrs @In EntityManager (S

msystems do-not-reply at jboss.com
Thu Feb 7 13:54:57 EST 2008


"kasim" wrote : "msystems" wrote : Use @PersistenceContext if you are using EJB3 and if you need a new transaction (@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) ) - Seam ref:
  |   | 
  |   | anonymous wrote : 
  |   |   | If you are using EJB3 and mark your class or method @TransactionAttribute(REQUIRES_NEW) then the trans- 
  |   |   | action and persistence context shouldn't be propagated to method calls on this object. However as the Seam- 
  |   |   | managed persistence context is propagated to any component within the conversation, it will be propagated to 
  |   |   | methods marked REQUIRES_NEW. Therefore, if you mark a method REQUIRES_NEW then you should access the en- 
  |   |   | tity manager using @PersistenceContext. 
  |   |   | 
  |   | 
  |   | otherwise use SMPC.
  |   | 
  | 
  | What you are saying at the top part is true.
  | 
  | However i don't believe the doco is saying use SMPC all the time.
  | 
  | Take a look at the first paragraph of the section. It basically refers to if you are using the component outside of a Java EE5 environment or if you have many loosly coupled components. Which as long as they are all SB the PersisetnceCOntext should transfer. However the doco is 100% right if you are going to have a mix of SB and POJOS .... then yeah doing the EntityManager injection is the only way to go.
  | 
  | So you can stick with the @PersistenceContext in most situations. Its going to be a situation where you are wanting to transact against non-EJB components you will want to use the @IN EntityManger. 
  | 
  | Of course that being said i am not sure the harm it would cause using the @In EntityManager more often.

Of course you don't have to use SMPC if you don't want to use it !
But there is an advantage in using SMPC if you have a lot of conversations with loosly coupled components.

98% of the time I'm using a SMPC and the last 2% of the time I'm using a persistence context (@PersistenceContext) - of course together with Seam-managed transactions.



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4127541#4127541

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4127541



More information about the jboss-user mailing list