title: Obtain column data from One-To-Many join relation in Spring data JPA
body: <p>Suppose I have two database tables, Product and ProductDetails.</p>
  
  <pre><code>create table Product
  {
      product_id int not null,
      product_name varchar(100) not null,
      PRIMARY KEY (product_id)
  }
  create table ProductDetails
  {
      detail_id int not null,
      product_id int not null,
      description varchar(100) not null,
      PRIMARY KEY (detail_id,product_id),
      FOREIGN KEY (product_id) REFERENCES Product(product_id)
  }
  </code></pre>
  
  <p>Each product can have multiple product detail entries, but each product detail can only belong to one product. In SQL, I want to be able to retrieve each product detail but with the product name as well, and I would do that with a join statement.</p>
  
  <pre><code>select p.product_id,pd.detail_id,p.product_name,pd.description
  from Product p join ProductDetails pd on p.product_id=pd.product_id
  </code></pre>
  
  <p>Now I need to have that concept in Spring data JPA form. My current understanding is the following:</p>
  
  <pre><code>@Table(name = "Product")
  public class ProductClass
  {
      private int productID;
      private String productName;
  }
  
  @Table(name = "ProductDetails")
  public class ProductDetailsClass
  {
      private int detailID;
      private int productID;
  
      // this is the part I don't know how to set. @OneToMany? @ManyToOne? @JoinTable? @JoinColumn?
      private String productName;
  
      private String description;
  }
  </code></pre>
  
  <p>(I didn't include any attributes such as <code>@Id</code> to keep the code minimal)</p>
  
  <p>What do I need to write to get this <code>private String productName;</code> working?
  My research on the <code>@JoinTable</code> and <code>@OneToMany</code> and other attributes just confuses me more.</p>
  
  <p>P.S. This is a legacy Java program I inherited. The <code>private String productName;</code> part wasn't in the original code, but now I need the ProductDetails class to have the <code>productName</code> available.</p>
  
  <p>P.P.S. I want to have a clear understanding of what I'm doing before trying anything and deploying. This is a legacy program deployed to production, and from what I understand, any code changes here can change the database structure as well, and no amount of money is enough to make me want to restore the Java program, the Spring Framework, the Apache server and MySQL database to a working order if anything catastrophic happens. Also I don't really have a development environment to test this. Help...</p>