Quantcast
Viewing latest article 10
Browse Latest Browse All 1091

EJB and container getting different connections

I have an issue relating to EJB and database connections under Glassfish, and I can't understand why I can't find plenty of others hitting the same issue, but all my searching has proved fruitless. I would assume this to be more of a Glassfish than a Hibernate question, but hopefully someone can advise on here.

I have a relatively simple setup which is a Hibernate based application using CMT deployed under Glassfish. I have a couple of routes into this application, GUI and WS, and both come in through an EJB call. In order to facilitate multiple EJBs running within a single transaction, I've setup an Oracle XADataSource in a Glassfish connection pool. This all works well except I notice one thing which has caused problems for us. The issue is that any database interactions via the EJB consistently interact with the same underlying connection (which is great), but as soon as the container takes over for the commit, it consistently receives a different connection. A flush at the end of any EJB work can avoid any issues, but if any work is left unflushed on EJB completion and is handled instead by the final commit, this now happens under a different (isolated) connection.

It would seem odd to me that the container would want a different connection to the rest of the transaction, but having debugged in the Glassfish code it seems to very purposefully behave like this. At commit, the connection in use by the EJB is marked as busy and unavailable as a free resource. The allocation this time round is not against the transaction, so simply looks to pick up a free resource, which will be a different connection.

I'd be most grateful if someone could enlighten me on what's going on here. I really can't understand why this isn't more of a problem for more people. Thanks

Glassfish 3.1.1, Hibernate 3.5.6, Oracle driver ojdbc14.jar


Viewing latest article 10
Browse Latest Browse All 1091

Trending Articles