Solved

ejbCreate() problem

Posted on 2001-09-03
6
172 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb entity bean example 2 52
ejb mdb examples 1 35
program arguments vs VM arguments 4 54
How to fix  socket closed error 11 59
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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…
Suggested Courses

740 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