Solved

ejbCreate() problem

Posted on 2001-09-03
6
166 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
json example 39 130
java  and programming certification ? 4 86
Unable to start eclipse ? 17 128
eclipse formatting 6 70
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.

930 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now