Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How does JPA manage sessions / connections?  RSS feed

Mike Cheung
Ranch Hand
Posts: 113
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm trying to understand when my code will actually make a connection to the database. Are the following true?
1) Calling em.getTransaction().commit() or em.close() will connect to the database.
2) Calling em.close() will disconnect from the database.

If I have a web application, and I have only created one EntityManager at start of the application to be used by all users from different locations, and each of these users can make calls to the database, would the EntityManager line up all the requests in series or initiate multiple connections to the database for each of the requests?

From the following posts it appears mixing multi-thread with a JPA provider can be nasty. So would the same thing happen to a web based application?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!