title: How do i properly cache common objects / entities when using JPA?
body: <p>I have a web app that needs to load some rows from tables in my database as objects that will be re-used in various places within the application.</p>
  
  <p>For instance, I might retrieve a list of locations that change infrequently, so I want to store those in memory for quicker access later on.</p>
  
  <p>Next, in a future request, I want to associate one of these entities to another entity in the database; however, JPA throws errors when attempting to save, because the cached entity is detached.</p>
  
  <p>How do I reattach the cached entity so I can include it in the current transaction?</p>
  
  <p>I'm using the Apache OpenJPA implementation.</p>