facebook

JPA closeEntityManager

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #282418 Reply

    mrossix
    Member

    Why you never close the EntityManager in yours dao’ s implementation?
    Wo close the jdbc connection in a Resource-Local environment?

    Thanks,
    Marco

    #282482 Reply

    Riyad Kalla
    Member

    Marco,
    I’ve never seen a document that suggested you close the EM between invocations, I believe that would be a very expensive operation. Do you have a doc you are referencing that suggests that?

    #282553 Reply

    mrossix
    Member

    In the ejb-3.o specification – page 120 – you’ll find an example. Usually i use hibernate as persistence library, and i have to close the hibernate session (witch close the jdbc connection).
    In JPA i don’t understand who close the resources, in particular the jdbc connection. Or, using a connection pooling, who return the jdbc connection object to the pool.

    Thank for your reply,
    Marco

    #282643 Reply

    mrossix
    Member

    Another example; take a look at the book “Java Persistence with Hibernate” – Manning in the JPA examples.

    Marco

    #282682 Reply

    Riyad Kalla
    Member

    In JPA i don’t understand who close the resources, in particular the jdbc connection. Or, using a connection pooling, who return the jdbc connection object to the pool.

    The application server takes care of all of this as long as you use a JNDI-bound data source. When working with an app server it is generally suggested you do just that.

    #282783 Reply

    mrossix
    Member

    “Managed entity instances are monitored. Every modification you make to an
    instance in persistent state is at some point synchronized with the database
    (unless you abort the unit of work). Because the EntityTransaction is managed
    by the application, you need to do the commit() manually. The same rule applies
    to the application-controlled EntityManager: You need to release all resources by
    closing it” – from Java Persistence with Hibernate [Christian Bauer, Gavin King].

    What do you think?

    #282842 Reply

    Riyad Kalla
    Member

    This message has not been recovered.

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: JPA closeEntityManager

You must be logged in to post in the forum log in