Search code examples
javajpatransactionsentitymanager

Entity Not Found In DB but present in Persistence Context


I'm creating a resource subscription using transaction 1, before this transaction 1 returns , it adds the request , response and jpa query fetched just created subscription resource into a queue which is taken care by by executor service threads.

This executorService starts separate transaction 2, a uses to jpa query to read a specific attribute of subscription resource ,but it gets null value , but the previous transaction 1 found it(coz may be it itself created it). Transaction 2 need to read the current value but not founding it.

I'm using Ecliplink 2.6, JDK 1.8 and Wildfly 10.Final.

I have looked into whether eclipselink have persisted it to DB or kept in persistenceContext coz, transaction is still not complete and new transaction trying to read it.


Solution

  • That's normal transaction behavior.

    As long as T1 is not commited T2 cannot see the data from T1.