The question is specific to caching in Persistent Context(L1) and not to second level cache.
I want to know why entity in the cache of Persistent context are not refreshed on selection/re-loading of entity using JPQL.
Explanation of question using example:
I verified in the logs that query was fired. Then why was entity A not refreshed?
This is the way first level cache works. When OpenJPA reads the result set of the query, it checks the id field of the result set row. If the entity with that id is already present in the persistence context, the existing entity is used and the rest of the result set row is ignored, meaning that the entity is not assembled again.
If you want to force reloading of an entity instance, you can:
Depending on the use cases, you may want to flush any changes you may have done in the instances you intend to refresh/detach/clear before applying any of the above operations, otherwise those changes will not be synchronized with the database.