Solved

ejbCreate() problem

Posted on 2001-09-03
6
165 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

707 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

16 Experts available now in Live!

Get 1:1 Help Now