• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

entity manager doubt

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the spec, it says the entity manager is used to bring the persistence context to work.

If so, then why is there seperate kinds of persistence contexts and different types of entity managers? Why cant they be the same as one makes the other work?? What is the difference between application-managed persistence contexts and application-managed entity managers? its very confusing...
 
Aditya Vasudeva
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please help.......
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
aditya,

one entity manager manages a persistence context. A persistence context is like the scope of variable in java programs:

local variable: TRANSACTION persistent context

instance variable: exyended persistent context

entity manager is like JVM in java application managing these scopes.

so if you have entity in transaction context scope thn entity manager keep track of it (manage) it till the commit of transaction just like JVm keeps local variable in scope till the method ends.

similarly in extended context, entity manager keeps track of entities spanning multiple method calls/transactions just as in the case of instance variable visibility in a class.

in case of CMT(container managed transaction), a transaction starts and ends with method, in case of BMT(bean managed transaction) it spans multiple methods between the UserTransaction.begin() and commit()/rollback().

Also transaction helps carrying persistent context to propagate it to other components.

the reason why these two type of entity managers are there is to provide flexibilty when developing, EXTENDED can only be used with stateful session beans because transaction can start in one mthod and end in another.

hope tht helps...
 
Aditya Vasudeva
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you vinay. That was a good explanation.

So it basically means that container-managed entity managers can manage container-managed persistence contexts and app-managed em can manage app-managed persistence contexts. Right??
 
Vinay Nath
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are welcome my friend.

yup, and also container managed em can be of 2 types TRANSACTION & EXTENDED.
and Apllication em/persistent context dont get propagated with transactions.
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To Add this,
Entity Manager is something like JDBC Driver. From JDBC driver you get the connection for the Database. Like this, EntityManager gives you the persistent context which you can use to talk with the database.
Please correct me if I am worng.
 
Aditya Vasudeva
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you vinay. I think you're right, Krishna.
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic