This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Joe Ess
  • salvin francis
  • fred rosenberger

Standard way to handle Repository in JPA

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Consider the following scenario.

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.

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).

This the way I currently handle repository caching which I can use throught the application life cycle.

Is there any standard way provided/supported in JPA/Hibernate to achieve/implement this requirement.

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).

Please help me in this regards as what is the standard way to be followed in jpa for this.

We're all out of roofs. But we still have tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!