I have a web application that consists of a web service with two operations: `createA` and `createB`. An handler is registered for the endpoint. This handler opens a Session and start a transaction when the request is received. Then the code of the requested operation is executed. Before the response is sent back, the transaction is committed and the session is closed.
The code of `createA` consists of creating an entity of type `A` and persisting it using `Session.save()` method. In DEBUG mode, after `Session.save()` is called, I can see that there is one insertion in the ActionQueue of the session.
The code of `createB` consists of :
- retrieving the previously created entity of type `A` - creating an Entity `B` that references the instance of `A` (B has a property that represents an associated `A`) - updating `A` to reference the new instance of `B` - call `Session.save()` for the new instance of `B` - call `Session.update()` for the new modified instance of `A`
However, in DEBUG mode, after calling `Session.save()` and `Session.update()`, the ActionQueue of the corresponding Session is empty. But, after the transaction commits, I can see the created entity in the database.
Operation `createA` and `createB` are invoked in this order without DEBUG. An error appears during the execution of the create `B` when it tries to retrieve the instance of `A` previously created using a criteria and the `Session.list()` method. The problem is that the instance of `A` is not found.
However, if I repeat the same sequence of operations in DEBUG or using `Thread.sleep(15s)` between invocations of the two operations, the instance of `A` can be found.
I also precise that it works on certain machines but not on others. And I don't see any differences between these machines.
Thanks
|