title: JPA - What's the best practice way to load static data from a Database lookup table?
body: <p>I have a lookup table in my relational database schema called UserRole where it has the following table columns:</p>
  
  <pre><code>Role_Id | Role_Name | Role_Desc | (some other foreign key ids linking to other tables) |
  -------------------------------------------------------------------------------
  1       | Admin     | Admin user| ......                                               | 
  </code></pre>
  
  <p>All rows in above table are static data (they never ever change in my application) </p>
  
  <p>At the moment i have an Entity persistent object:</p>
  
  <pre><code>@Entity
  @Table(name = "UserRole")
  public class RoleEntity {
  
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "Role_Id")
  private int id;
  
  @Column(name = "Role_Name")
  private String role_name;
  
  @Column(name = "Role_Desc")
  private String role_desc;
  ....
  
  // other code omitted for brevity
  }
  </code></pre>
  
  <p>I have an equivalent Repository class which just fetches the data: for e.g.</p>
  
  <p><code>entityManager.find(...).getResultsList()</code> etc...</p>
  
  <p>................................................................</p>
  
  <p>Every time when i need to use these roles i am making a call to the database directly. I feel there is no need for this because the data never change in my case. I thought of storing the data in an Enum instead and not have that data in the database but the data is already part of a legacy system and i can't change the database design plus that table already has many links to other tables.</p>
  
  <p>I want to load them only once maybe at startup.</p>
  
  <p>What is the best way to do this?</p>
  
  <p>Is it simply just have like a singleton class to maintain a (static?) list of all the roles, and after initialising, use the Repository class to make a call to Database to fetch the data into the list in memory.?</p>