Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When to open / close Datasource connection in EJBs

 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm pretty new to the whole EJB scene, so please excuse my ignorance.
I'm thinking of using the Session Facade pattern for our EJB application, with bean-managed EJBs. The entity beans will look up container-configured datasource (oracle8 db) with JNDI and use that for persistence. The question I have is, at what point should the datasource connection be created and closed? As I understand, the container (jboss 4.0.0) will pool existing connections and lend them to the entity beans upon lookup. Does this mean the entity beans shouldn't close the connection on their own?

Thank you in advance,
Yuriy
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In BMP beans, you should open and close database connections in each of create(),load(),store(),findBy..(). closing a connection just return the connection to connection pool, it won't actually close the connection with database. Its handled internally by ConnectionManager.
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great, thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic