• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on PersistenceContext

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Whys is that only those EntityManager instances injected with the @PersistenceContext annotation are transaction-scoped?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean, why application-managed persistence contexts are not transaction-scoped ? You don't want the container to mess up with your application-managed stuff (EntityManager, persistence context), do you ? You are the one who controls the scope of the entity manager and its persistence context. You are the one who must close the entity manager. Why would you need a transaction scope ?
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I agree, as Christophe says, that an application-managed persistence contexts must be managed by the application(as its name says )

Additionally, when a JTA application-managed entity manager is used, if the entity manager is created outside the scope of the current JTA transaction, it is the responsibility of the application to associate the entity manager with the transaction (if desired) by calling EntityManager.joinTransaction.

For resource local transactions, the entity manager should start and commit the transaction by itself. Please see "5.7 Application-managed Persistence Contexts" of ejb-3_0-fr-spec-persistence.
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jothi,

See the reply by Ralph to your thread "EntityManagerFactory vs EntityManager".

He has given a good explanation on this.

Regards,
Cham
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic