title: How to model lookup tables JPA
body: <p>I'm trying to build a Spring Boot data layer on top of another project's DB. I'm want to get to a point where I can consume their data via Restful endpoints rather than directly from the DB. Maximum abstraction is the goal. Here's my problem. Consider the following JPA entity:</p>
  
  <pre><code>@Entity
  @Table(name = "PERSON", schema = "public")
  public class Person {
  @Id private long id;
  private String name;
  private long favoriteFood;
  private Address address;
  
  //Getters, Setter etc.....
  }
  </code></pre>
  
  <p>Notice that favoriteFood is a long, not a String. This is because the DB uses a lookup table. Let's say Joe's favorite food is pizza. The person table stores a 1 in the favorite_food column which is the fk to the "pizza" value stored in the food_ref table. This pattern is repeated hundreds or times in the DB. What is the best way to model this in JPA/Hibernate? Change the variable to String and have the getter and setter do the lookup? I've not found any examples which seems strange. This is a common DB structure. Any advice on best practices would be appreciated. Thanks!</p>