Solved

ejbCreate() problem

Posted on 2001-09-03
6
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 

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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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…

688 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