Spring Boot jpa join column on date condition

Viewed 238

I'm using Spring Boot Data jpa and have defined entities structure like below:

Class Parent {
  @EmbededId
  private ParentId id;
  @OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="parentDetails")
  private List<Child> childDetails;
  ...
}

@Embeddable
Class ParentId {
  private Integer pid;
  private Date startDate;
  private Date endDate;
  ...
}

Class Child {
  @EmbededId
  private ChildId id;
    @ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
    @JoinColumns({
      @JoinColumn(name="cid" referencedColumnName="pid")
      @JoinColumn(WITH_DATE_COLUMN)
    )}
  private Parent parentDetails;
  ...
}

@Embeddable
Class ChildId {
  private Integer cid;
  private date cdate;
  ...
}

My select query is like below:

select * from Parent p 
join Child c on p.pid=c.cid1 and (c.cdate > p.startDate and c.cdate < p.endDate)

I made till like above, but I am not sure how to add the join condition based on the date like specified in query in place of WITH_DATE_COLUMN. Is there any solution for this?

0 Answers
Related