Note that there are some explanatory texts on larger screens.

plurals
  1. POStandard way to handle Repository in JPA
    primarykey
    data
    text
    <p>Consider the following scenario.</p> <p>There is a table in db whose content together form as a repository. This table will be updated (updation of existing extities, addtion of new entities or removal of entities) rarely. So currently the approach that I was using was to create a singleton XXXRepository pojo which will read all the rows (entities) from XXX table and store them in a map.</p> <p>If someone is updating the XXX table then after the update part of code is executed, a post runnable will run which will clear the repository (map) and hence next time any entity is being located from the map, the loadRepository will be invoked (as the map will be null).</p> <p>This the way I currently handle repository caching which I can use throught the application life cycle.</p> <p>Is there any standard way provided/supported in JPA/Hibernate to achieve/implement this requirement.</p> <p>I went through the caching mechanism (both 1st and 2nd level cache). But it seems to be for entities or queries or data and for different purpose/approach than what is expected to be happening or achieved by Repository. Also if we are able to achieve this somehow by using 2nd level cache, then there is one more issue that cache updates only in case of jpa operations and jpql queries. In case of jdbc or native queries it will fail to be updated and we will have stale data (correct me if I'm wrong).</p> <p>Please help me in this regards as what is the standard way to be followed in jpa for this. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload