Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question

Annotated Declarative Transactions and Remoting


I know there was a thread on this topic previously but I have been unable to find the resolution.

I'm struggling to find the magic code/configuration to make annotated transactions work with a remoted service. Shay suggested I post an example, so I am attaching the code and config for my PU and client. The pu.xml that I am posting activates spring tx: support explicitly. I have also tried it without including this, and gotten the same results.

The behavior I expect from the attached example is for a 10 second transaction to occur every time I run the client. During those 10 seconds I would expect the instance count in the space to reflect the insertion of the new object, but I would not expect to be able to see the new object in query results. I would also expect to see an active transaction in the space browser. Instead I am seeing the new object inserted and visible immediately, and no sign of a long-running transaction.

I would greatly appreciate it if someone could explain what I have done incorrectly and how to correct my error.

Many thanks.


Edited by: Dan Stone on Feb 22, 2009 3:23 AM h4. Attachments












{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=2896]{quote}

asked 2009-02-22 03:19:34 -0500

subuta gravatar image

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2009-02-22 04:44:58 -0500

uri gravatar image
edit flag offensive delete link more


Hi Uri,

That's weird. I'll upload the files again.

I have been looking at the doc, and I wonder whether the problem is that the client is not initiating a transaction.

-Dan h4. Attachments






subuta gravatar imagesubuta ( 2009-02-22 07:20:47 -0500 )edit

Hi Uri,

That's weird. I'll upload the files again.

I have been looking at the doc, and I wonder whether the problem is that the client is not initiating a transaction.

-Dan h4. Attachments







subuta gravatar imagesubuta ( 2009-02-22 07:23:35 -0500 )edit

Hi Dan

Your configuration looks ok. The reason you're seeing the object is that
the space browser uses dirty reads, so in fact it shows uncommitted
objects in the object count.
This is implemented that way for performance reason and to avoid any
locking of the space by the UI.
To make sure you are getting the desired behavior, do the following in
the TranDemo class:
1. Write an object to the space
2. Wait for x seconds
3. Throw a deliberate RuntimeException
In the UI, you should see the object count return to 0.
Alternatively, you can return normally and see that the object stays in
the space. To demonstrate atomicity, you can write more than one object
to the space and verify that either all instances are written or none at

You can do it by changing the signature and implementation of the
TranDemo class as follows:

@Transactional (propagation = Propagation.REQUIRED)
public void doWork(int numInstances, boolean throwException) {
    for (int i=0; i<numInstances; i++) {
        gigaSpace.write(new Object());
    try {
        System.out.println("\nSleeping inside a transaction (I
    } catch (InterruptedException e) {
        System.out.println("\nAwakened while killing time");
    if (throwException) {
        throw new RuntimeException();


  1. pu.xml
uri gravatar imageuri ( 2009-02-22 09:49:36 -0500 )edit

Hi Uri,

Thanks for the explanation and the advice. I'm not sure, though, that we have bottomed this out quite yet:

I am still struggling to understand why I can't see the transaction in progress during the sleep.

If I set propagation to mandatory I don't get a runtime error as promised by Spring.

When I throw an exception from within the service method the row that was just inserted does not disappear.

Taken together these points suggest that there is no transactionality. Please let me know what you think.

BTW, here is a link the other post I referred to that discusses this same topic: /[/question/4047/remoting-services-and-transactions/]

Here is my code as modified it to throw the exception.


import org.openspaces.core.context.GigaSpaceContext; import org.openspaces.core.GigaSpace; import org.openspaces.remoting.RemotingService; import org.springframework.transaction.annotation.*;

@RemotingService public class TranDemo implements TranDemoInterface {

private GigaSpace gigaSpace;

@Transactional (propagation = Propagation.MANDATORY)
public void doWork() {
    gigaSpace.write(new Object());

    try {
        System.out.println("\nSleeping inside a transaction (I hope)");
    } catch (InterruptedException e) {
        System.out.println("\nAwakened while killing time");
    throw (new RuntimeException());

} h4. Attachments


subuta gravatar imagesubuta ( 2009-02-22 11:45:57 -0500 )edit

Hi Uri,

One additional point that I forgot to mention with regard to the browser and dirty reads. My experience with it has been that it shows changes in instance counts during transactions as you said, but I think that the query feature will not show the contents of a new entry until transaction commits. When using annotations, though, I can see the contents of the row during the sleep period. This is another piece of evidence that suggests that there is no transaction.

-Dan h4. Attachments


subuta gravatar imagesubuta ( 2009-02-22 12:03:31 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2009-02-22 03:19:34 -0500

Seen: 61 times

Last updated: Feb 22 '09