Serialization and transaction problem.

Hi there,

I have two problems:

EJB Transaction:
I am currently using Tamino’s Java EJB API, and in some cases I get the Exception “there is no tamino transaction associated with this thread”. How does the API manages thread/connection relationship? In my logs, there is only one thread that is:
1- Creating the transaction (via UserTransaction)
2- Opening the connection
3- Processing
4- Closing connection
5- Committing transaction.

What information from the thread is the Tamino API using? is it using the Thread’s hash? or its thread group? Thread.toString() ? any help would be greately appreciated.

EJB Serialization:
When my Stateful session beans are being serialized I get a NotSerializableException on Weblogic 7.0, aparently the Transaction object that is being used in the bean is not serializable, which is a ServerTransactionImpl.

Thanks in advance for any help,

– Juan

Hello Juan,

The exception “there is no tamino transaction associated with this thread” may come in two situations:
1. You are trying to obtain an accessor and the transaction is already terminated.
2. You are trying to end a transaction which has already been terminated.

The Tamino EJB API always maintains a connection and a transaction with Tamino. It is as if you had issued useLocalTransaction(). The Tamino transaction is terminated when the Tamino EJB API gets told by the application server to commit or rollback.

Make sure that the TEJBConnection you obtained is only used in one EJB transaction. Once that transaction is terminated you can no longer use that TEJBConnection. You need to acquire a new one.

When passivating you need to be serializable. SO, you need to drop all references to non-serializable objects. In particular, you can not hang on to transaction context objects or connections.

Another hint: with Tamino 3.1.2, we have introduced a JCA implementation (the Tamino Resource Connector). With Tamino 4.1, the Tamino EJB API will be deprecated. Eventually we will only provide EJB support via the Tamino Resource Adapter. I would suggest to start using the Resource Adapter if you can.

regards
Martin

Thanks Martin,

I’ve checked it, transaction is open and not committed. I found the problem though, I was starting the transaction by calling a method startTransaction on a Stateful bean which calls getUserTransaction().begin(); and from that code (the initial caller) I was trying to get an accessor. Apparently the thread group changes or there is some relationship between the stack trace and the way transactions are monitored, but when the transaction is started from a point that cannot be traced back from the statement that is creating the accessor, the implementation seems to fail.

To describe it better:

- Main -> statefulbean.startTransaction() -> getUserTransaction().begin

- Main -> EntityBean->ejbLoad() -> getAccessor() – *** FAILS!!!

Now, to solve it:

- Main -> statefulbean.startTransaction() -> getUserTransaction().begin
- Main -> statefulbean.doWhatever() -> EntityBean->ebjLoad() -> getAccessor() – WORKS!!


So, that solved that part of the problem.

On the other hand, I keep having the serialization problem. In my stateful bean, there are no references to any non-serializable object, and the exception is thrown by an object which is Weblogic’s implementation, called ServerTransactionImpl(). So, is that object probably hanging a reference to Tamino’s implementation that is not serializable?

Thanks,

– Juan

Hi Juan,

I am not sure I understand exactly what you mean.

The exception message “there is no tamino transaction associated with this thread” is confusing in its wording. It hasn’t really anything to do with threads. It is better to read something like: “there is no tamino transaction associated with this BEAN”.

You always need to follow the following pattern:
1. start an EJB transaction (either via UserTransaction.begin or via Container demarcation).
2. acquire a new TEJBConnection
3. get accessors and do some work
4. close the TEJBConnection
5. end the transaction

If you have several beans that participate in the same transaction, you need to make sure that the transaction context that is started in one bean is passed on to the others. This is done simply by the fact that you call the other beans from the bean that started the transaction (assuming that you have set appropriate transaction properties for the called methods, like “Supports transaction”). You can pass a reference to the TEJBConnection object from bean to bean or you can issue a separate lookup in each bean. Mind you that the latter functionality is not very well defined using the Tamino EJB API. It is much better defined in the Tamino Resource Adapter.

Concerning the serialization issue, I do not think that WebLogic is hanging on to any of our objects. Make sure that you set any references to transaction context objects and TEJBConnection objects to null before you are passivated.

regards
Martin

Martin,

Thanks. Following your advice, I have moved my DB access methods to use the JCA. Still have the same Serialization problem, but is seems to be on Weblogic’s side, not on Tamino’s implementation.

Thanks for your answers, they helped a lot.

Regards,

– Juan