title: How to establish foreign key relationship with a non entity table in the database using Spring data JPA?
body: <p>My spring boot project uses an existing database, I have a new model entity/table in my project that must have a foreign key constraint with an existing table in the database. </p>
  
  <p>I've tried to find solution online but all the answers are for the case where both the tables are present as entities in that project and using some @ManyToOne, @OneToMany annotations. </p>
  
  <p>I can't define those annotations because I don't have the reference table as an entity or model in my project.</p>
  
  <p>Let's say I have class like: </p>
  
  <pre><code>@Entity(name = "user")
  public class User {
      @Id
      @GeneratedValue
      private long userId;
      private long departmentId;
  </code></pre>
  
  <p>I want to put a foreign key contraint on the <code>departmentId</code> column to reference to <code>id</code> column of the existing <code>department</code> table that isn't defined as a model or entity in my project.</p>
  
  <p>Thanks</p>