title: How to retrieve parent entity using child entity-Spring data JPA
body: <p>Here is the DB table structure with one-to-many relation. EMP_DETAILS and MODEL_DETAILS are connected with action_id with a one-to-many relationship.</p>
  
  <p>Below are the entities create for both child and parent tables.</p>
  
  <p><strong>EmpDetails.java</strong></p>
  
  <pre><code>@Table(EMP_DETAILS)
  @Entity
  public class EmpDetails{
  
   @Id
   @Column(name="eid", nullable=false)
   private Integer eid;
  
   @OneToMany(cascade=CascadeType.ALL, mappedBy="empDetails"
   private Set&lt;ModelDetails&gt; modelDetailsSet;
  
   //other column mappings
  }
  </code></pre>
  
  <p><strong>ModelDetails.java</strong></p>
  
  <pre><code>@Table(MODEL_DETAILS)
  @Entity
  public class ModelDetails{
  
    @Id
    @Column(name="id)
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer id;
  
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="eid",referencedColumnName="eid", nullable=false)
    private EmpDetails empDetails;
  
    @Column(name="model_name")
    private String modelName;
    @Column(name="created_on")
    private Date createdOn;
    //Other column mappings and getters setters
  
  }
  </code></pre>
  
  <p>The below method does returns me the Model_Details records.</p>
  
  <pre><code>List&lt;ModelDetails&gt; modelDetailList=findByModelNameOrderByCreatedOnDesc("Any_Existng_Name");
  </code></pre>
  
  <p>But when we try to get the parent record related to the child record I get null like below..,</p>
  
  <pre><code>modelDetailList.get(0).getEmpDetails();//THIS RETURNS NULL!
  </code></pre>
  
  <p>Any solution for this</p>