0

I've got a problem in my Java EE app - in general, I persist one object, send a JMS, and on MDB I'm trying to find that object - sometimes it works, but sometimes I receive null on JPA find. I suspect that transaction didn't finish, but I can't find solution for this.

I'm not sure if I understand correctly - in CMT, transaction starts in the moment of invocation a method of Session Bean from @Local or @Remote interface? What if I have a chain of methods in this Session Bean and only one of them persist my object - does all chained methods will be invoked in one transaction? What if some of them are also exposed in interface?

Sending JMS is one of the chained methods - should I rather also expose this method in interface and call it after method that persist my object? What if I wouldn't want to expose that method in interface?

Sorry for any lack of EJB knowledge. Thanks for any help :)

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140

2 Answers2

0

Did you persist and find your object with the same entity manager?

You can always find your object if you are in the same transaction which persists the object before. If you persist and find the object with different transactions, then you cannot see the object until persisting transaction is committed.

My suggestion is: Use the same transaction, so that you can always find out your object. Or in Java EE applications, just simply use the same entity manager.

Ronson
  • 479
  • 2
  • 4
0

I suggest you don't write logic in MDB bean, use session bean for that, and just inject it into MDB. About method invocation, if you are calling a method in the same class and even if by giving @REQUIRES_NEW attribute it will not open a new transaction. In order to do it, inject bean itself and call injected bean, and that will open new transaction.