Solved

ejbCreate() problem

Posted on 2001-09-03
6
168 Views
Last Modified: 2013-11-24
I am using WebSphere 4.0 and when I have an entity bean with 2 sql queries in it I loose my data connection for the second query in the ejbCreate() method.  If I just have one query then it is fine but because I do 2 inserts for some reason the second one will not work.  Any ideas?

Thanks
0
Comment
Question by:cooder
6 Comments
 

Expert Comment

by:psvinayram
ID: 6452086
could u paste ur code here.
0
 
LVL 2

Accepted Solution

by:
Veroland earned 200 total points
ID: 6452422
According to WAS documentation after ever call you make on your connection (if you are using the containers connection pooling) the connection is closed, or more correct the connection is returned to the connection pool. Calling the close method on a connection also returns it to the pool.

You have to do a getConnection after each call to your db.

This was in WAS 3.5.3 doumentation but I suspect it will still be the same.

Mav
0
 

Expert Comment

by:raghu_k_n
ID: 6452672
I want suggest that if u say get connection for the second time, the connection might not be the same as the one used to execute the first query. So if u need some transactional support, u have to explicitly specify in the deployment descriptor(Same connection will be used for both the quires).

-HTH
Raghu
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:cooder
ID: 6453250
I will post the code around lunch.  But I make my connection like this:

public void setEntityContext(EntityContext context) {

      this.context = context;
      try {
         makeConnection();
      } catch (Exception ex) {
          throw new EJBException("Unable to connect to database. " +
             ex.getMessage());
      }
   }

Shouldn't the connection be good for the lifetime of the bean if you create your connection in the setEntityContext() method and close the connection in the unsetEntityContext()?
0
 

Author Comment

by:cooder
ID: 6456978
Ok...  You were correct in that this was what fixed my problem.  Although it seems to be odd to me.  What if you have to loop around an insert?  You have to constantly grab and put back connections from the pool for each query?  Also where did you read this in the docs?

Thanks though.  You solved my problem.
0
 
LVL 2

Expert Comment

by:Veroland
ID: 6457889
Thanks, I found it in the infocenter. Was a while ago so I'm not sure where
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question