We have a servlet which invokes a stateful seesion bean.The session bean internally refers to an entity bean.Then entity bean is using a datasource .
We get a connection handle from the data source in the setentitycontext of the entity bean.
When we invoke 2 successive methods on the session bean from the servlet,the second method aborts with an SQLexception :
The transaction is no longer active - status :'committed'.No further JDBC access is allowed within this transaction.
Both the session and entity bean methods have 'Supports' as the transaction property.
We have tried using the UserTransaction context from the servlet;but that does not allow us to do successive method calls either.What is the technically correct way to resolve this problem.
Also,if JTA usertransaction context is used ,does it override the transaction attribute settings of the beans?
Thanks in advance.
-
servlet and transaction (6 messages)
- Posted by: rana nag
- Posted on: June 04 2005 12:35 EDT
Threaded Messages (6)
- servlet and transaction by Martin Straus on June 06 2005 13:31 EDT
- Use Required/RequiresNew attribute on the session bean by Biswa Das on June 07 2005 19:24 EDT
- servlet and transaction by Viktor Sadovnikov on June 08 2005 02:15 EDT
- servlet and transaction by sawan parihar on June 12 2005 23:13 EDT
-
servlet and transaction by rana nag on June 14 2005 04:22 EDT
- How you are obtaining connection? by Biswa Das on June 14 2005 03:10 EDT
-
servlet and transaction by rana nag on June 14 2005 04:22 EDT
- servlet and transaction by sawan parihar on June 12 2005 23:13 EDT
-
servlet and transaction[ Go to top ]
- Posted by: Martin Straus
- Posted on: June 06 2005 13:31 EDT
- in response to rana nag
You should use a transaction that spans multiple client requests... although i have NO clue about hot to do this.
Sorry...
Cheers and happy coding,
Martin -
Use Required/RequiresNew attribute on the session bean[ Go to top ]
- Posted by: Biswa Das
- Posted on: June 07 2005 19:24 EDT
- in response to rana nag
Not sure how "Supports" will work for you in both the layer.
Supports never creates a new transaction context and only allows if any previously created.
If serlet calls sessionbean.method1(),sessionbean.method2()
then no way you can put them into one transaction. unless you have one more layer like sesssion facade.
If there is no worries of transaction then just use "Required"/"Requires New" tran attribute on the session bean and you get going. -
servlet and transaction[ Go to top ]
- Posted by: Viktor Sadovnikov
- Posted on: June 08 2005 02:15 EDT
- in response to rana nag
We have a servlet which invokes a stateful seesion bean.The session bean internally refers to an entity bean.Then entity bean is using a datasource. We get a connection handle from the data source in the setentitycontext of the entity bean
I am not sure how you get connection handle from setentitycontext of the entity bean into your servlet. Anyway, setentitycontext bean runs without transactional context. So all update you do on that connection, will not participate in any transactions.
Do you want datasource update done in servlet to be a part of your session bean transaction? -
servlet and transaction[ Go to top ]
- Posted by: sawan parihar
- Posted on: June 12 2005 23:13 EDT
- in response to Viktor Sadovnikov
Hi,
I am not sure about your question it will be good if you can explain it in more detail.
You get a connection handle from the data source in the setEntityContext which runs without a transaction context but then what for you are getting the connection handle. You are using CMT right ?.
Servlet ---->> SessionBean -----> EntityBean(If it is CMT then only the transaction context will propogate).
So the scenario is servlet is calling a sessionbean which has a attribute of supports that means the method runs in an unspecified transaction context. In this case there is no guarantee that how the jdbc access will be done.
It will be good if you can change the transaction attribute of the session bean to RequiresNew and let the entity bean run in the transaction context of the session bean .
Hope that helps. -
servlet and transaction[ Go to top ]
- Posted by: rana nag
- Posted on: June 14 2005 04:22 EDT
- in response to sawan parihar
The servlet calls the following methods on the session bean in succession:
getEmployeeDetail();
getTimeDetails();
The sessionbean in turns routes the call to the corresponding methods in the entity bean.
I use JDBC connections in the entity beans to performs db queries.
When the servlet calls the methods in succession,the second call returns
SQLException in query: The transaction is no longer active - status: 'Committed'. No further JDBC access is allowed within this transaction.
The sessionbean has 'RequiresNew'and the entity beans have 'Supports'.This is my situation.
Now how can the servlet call the 2 moethods in succession? -
How you are obtaining connection?[ Go to top ]
- Posted by: Biswa Das
- Posted on: June 14 2005 15:10 EDT
- in response to rana nag
You say to be using JDBC.
I hope u are using BMT.
Most likely there is an fundamental violation of EJB usage.
Please paste your entity bean code.