aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Mixing JDBC and CMP code -> leaked connections 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 "Mixing JDBC and CMP code -> leaked connections" Watch "Mixing JDBC and CMP code -> leaked connections" New topic
Author

Mixing JDBC and CMP code -> leaked connections

David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
I'm running in WebLogic 7.0sp4 on a two-node cluster, but the problems I'm seeing have raised some generic J2EE questions in my mind (IOW, not WebLogic-specific).
My EJB app uses a mix of SLSBs and CMP 2.0 entity beans with container-managed transactions, but one of the bean's create methods calls a SLSB to retrieve the next value from an Oracle sequence using JDBC. The whole system is setup to use a single TxDataSource. Somewhere, connections are being leaked. As usual, I suspect my own code first; then I look elsewhere. There are a few things that look suspicious in the sequence service SLSB, but first let me lay out my assumptions to see if I've just misunderstood the EJB spec.
1. It's okay for JDBC code and CMP beans to use the same TxDataSource.
2. Assuming (1) is true, if a SLSB method marked "Supports" gets called, the connection it acquires from the datasource will be enlisted in the current transaction if there is one. [I think this is my error]
3. If (2) is true, the SLSB method should interact with the connection as any other basic JDBC code would (getConn, execute query, close results, statement and connection). To wit:

Since obtaining the next value from an Oracle sequence is executed "outside" the database transaction (it cannot be rolled back), I marked this method as "Supports" -- it has no effect on nor requires an existing transaction. Is this correct, or must all database accesses be performed in the context of a transaction?
I'm beginning to think this is the problem -- that I must wrap a transaction around any code that will eventually interact with the DB or entity beans, even reading their attributes. I have all of the getters and finders on the entity beans marked as "Supports." Is this not the correct way?
Something that tells me I doing it wrong is that I have some startup code that reads in the lookup code table using entity beans (yes, I know it's overkill, but it should work). It simply does a findAll and iterates through the beans. This is the one place where I skipped creating a DTO in the bean and actually call the five getter methods on each bean. The SLSB method that does this work is marked as "Supports."
What I see is that each bean's ejbStore() method is called after each getter call. It's like WL is creating a transaction, accessing the bean's attribute, and then committing the transaction. I thought that by marking all methods involed with "Supports," no transaction would be begun or committed. Now it looks like WL insists on having an active transaction when accessing an entity bean for any reason. Is this the case?
Thank you in advance for any pointers. I know this is a pretty long and involved post, so if I can clarify anything or post more code, let me know.
Peace!
[ February 04, 2004: Message edited by: David Harkness ]
[ February 04, 2004: Message edited by: David Harkness ]
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
Originally posted by David Harkness:

My EJB app uses a mix of SLSBs and CMP 2.0 entity beans with container-managed transactions, but one of the bean's create methods calls a SLSB to retrieve the next value from an Oracle sequence using JDBC.

I believe you could avoid a lot of headache using the weblogic support for oracle sequences that u can add on the weblogic-cmp-rdbms-jar.xml file using:

take a look at:
http://edocs.bea.com/wls/docs81/ejb/entity.html#1155399
this link is for weblogic 8.1 but weblogic 7 already had support for this.
regards.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Marcos Maia:
I believe you could avoid a lot of headache using the weblogic support for oracle sequences

I should have been more clear (I've posted to a few forums already, so they're all bleeding together). The sequence is used for a non-PK column of that one bean. All the beans use WebLogic's built-in automatic PK generation.
I supposed if this turns out to be the problem (I'm still not convinced as this method is called by the one bean, and those beans are rarely created, and no news ones have shown up in the DB for the last month), I could create a temporary entity bean, grab it's PK, delete it, and use that value for the real bean. Ick! I hope it doesn't come to that.
Thanks though! We're launching to production tomorrow night, so I very much appreciate any ideas.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Mixing JDBC and CMP code -> leaked connections