I have a servlet that posts a message to a stateless session bean, which inturn updates DB. The problem is that it always commits after each insert regardless to whether I have done a UserTransaction.Rollback or commit.
The Session bean is:
The UserTransaction and Context are create (call getIC() and getUT()) on calling the ejbCreate and ejbActivate methods.
Your code and your settings look almost fine to me. I would also expect it to work. One might even suspect that the auto-commit feature is turned on, but that�s not the default with jta. There is however one more thing that looks wrong to me: the fact that your SLSB maintain the reference to the user transaction (ut) as an instance variable. Please notice that stateless means that the session bean does not maintain any state information for a specific client. However, stateless session beans can have non-client specific state like a database connection. Making your transaction object �sharable� I�m not pretty convinced is a good idea and you�d probably like changing the getUT method as follows (not to say that the synchronized keyword here is meaningless):
Besides I guess you declared ut as static and this makes no sense with ejbs (unless they are final). For the same reason I would advice you to rewrite the getIC() method and make ic non-static as well. Regards.
My vender is Orion. Looking at the documentation, it states I should be setting up the datasource as:
3.5 Configuring a vendor XA DataSource for EJB or CMT usage
In order to use a vendor implementation of a XA DataSource for EJB or CMT usage, the DataSource has to be wrapped by the OrionCMTDataSource class in order for Orion to add support for distributed transactions and pooling as necessary.
This setup requires two DataSource configuration entries; one defining the vendor XA DataSource and another defining the wrapping Orion DataSource (OrionCMTDataSource) for EJB or CMT usage.
Below is an example of such a setup using Inet Opta 2000 XDataSource for MS SQL Server 7.0:
Listing 5: A sample XA Datasource for EJB or CMT usage DataSource entry.
The first DataSource configuration entry listed above creates a Inet Opta2000 DataSource and binds it to the JNDI location " jdbc/vendorXACoredDS". The name of the database to use is stated in a parameter name-value pair as this parameter is not part of the normal parameters defined for data-source.xml entries, but the vendor's implementation needs this value.
The second DataSource configuration entry listed above creates a OrionCMTDataSource on top of the first DataSource and binds it to the JNDI location " jdbc/defaultCoreDS". As this DataSource needs to be used on top of a existing XA DataSource, the JNDI location value of the xa-source-location attribute is given a value of " jdbc/vendorXACoredDS", which will point it to the first DataSource (see above).
The second DataSource configuration entry listed above would become the default DataSource for all applications deployed after this DataSource descriptor has been deployed as its the first DataSource listed to use the OrionCMTDataSource.
I believe you�re right and I�m convinced the changes I recommended will not solve your problem. I remember somebody else on this forum having a similar problem and s/he solved it by setting the DataSource. He was using weblogic though and he needed to enable the TX-DataSource in order to honor the global transactions. Unfortunately I don�t know much about the Orion server and I cannot help you there. Check the documentation though. Regards.