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 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
You should use a transaction that spans multiple client requests... although i have NO clue about hot to do this.
Cheers and happy coding,
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.
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 beanI 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?
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.
The servlet calls the following methods on the session bean in succession:
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?
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.