aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes When to open / close Datasource connection in EJBs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "When to open / close Datasource connection in EJBs" Watch "When to open / close Datasource connection in EJBs" New topic
Author

When to open / close Datasource connection in EJBs

Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
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

Joined: Oct 18, 2004
Posts: 346
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

Joined: Dec 13, 2004
Posts: 429
Great, thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When to open / close Datasource connection in EJBs