title: how to delete the record from the join table in hibernate
body: <p>forum member </p>
  
  <p>I need one help from you all. I am having two POJO model with one to many relationship.
  <strong>my project pojo is below</strong></p>
  
  <pre><code>@Entity
  @Table(name = "project")
  public class Project implements java.io.Serializable {
  
      private Integer projectid;
      private Date enddate;
      private String projectdesc;
      private String projectname;
      private String projecttitle;
      private Date startdate;
      private Set&lt;Task&gt; tasks = new HashSet&lt;Task&gt;(0);
  
      public Project() {
      }
  
      public Project (Integer id,String projectname, String projecttitle, String projectdesc, Date startdate, Date enddate) {
          this.projectid = id;
          this.enddate = enddate;
          this.projectdesc = projectdesc;
          this.projectname = projectname;
          this.projecttitle = projecttitle;
          this.startdate = startdate;
      }
  
      public Project(Date enddate, String projectdesc, String projectname,
              String projecttitle, Date startdate, Set&lt;Task&gt; tasks) {
          this.enddate = enddate;
          this.projectdesc = projectdesc;
          this.projectname = projectname;
          this.projecttitle = projecttitle;
          this.startdate = startdate;
          this.tasks = tasks;
      }
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      @Column(name = "projectid", unique = true, nullable = false)
      public Integer getProjectid() {
          return projectid;
      }
  
      public void setProjectid(Integer projectid) {
          this.projectid = projectid;
      }
  
      @Temporal(TemporalType.TIMESTAMP)
      @Column(name = "enddate", length = 19)
      public Date getEnddate() {
          return enddate;
      }
  
      public void setEnddate(Date enddate) {
          this.enddate = enddate;
      }
  
      @Column(name = "projectdesc")
      public String getProjectdesc() {
          return projectdesc;
      }
  
      public void setProjectdesc(String projectdesc) {
          this.projectdesc = projectdesc;
      }
  
      @Column(name = "projectname")
      public String getProjectname() {
          return projectname;
      }
  
      public void setProjectname(String projectname) {
          this.projectname = projectname;
      }
  
      @Column(name = "projecttitle")
      public String getProjecttitle() {
          return projecttitle;
      }
  
      public void setProjecttitle(String projecttitle) {
          this.projecttitle = projecttitle;
      }
  
      @Temporal(TemporalType.TIMESTAMP)
      @Column(name = "startdate", length = 19)
      public Date getStartdate() {
          return startdate;
      }
  
      public void setStartdate(Date startdate) {
          this.startdate = startdate;
      }
  
      @OneToMany(cascade = CascadeType.ALL, fetch =FetchType.EAGER)
      @JoinTable(name = "project_task", joinColumns = { @JoinColumn(name = "projectid") }, inverseJoinColumns = { @JoinColumn(name = "taskid") })
      public Set&lt;Task&gt; getTasks() {
          return tasks;
      }
  
      public void setTasks(Set&lt;Task&gt; tasks) {
          this.tasks = tasks;
      }
  
  
  }
  </code></pre>
  
  <p><strong>and my task pojo is</strong> </p>
  
  <pre><code>@Entity
  @Table(name = "task")
  public class Task implements java.io.Serializable {
  
      private Integer taskid;
      private Integer depth;
      private Double duration;
      private String durationunit;
      private Date enddate;
      private Integer parentid;
      private Integer percentdone;
      private Integer priority;
      private Date startdate;
      private Integer taskindex;
      private String taskname;
  
      public Task() {
      }
  
      public Task(Integer depth, Double duration, String durationunit,
              Date enddate, Integer parentid, Integer percentdone,
              Integer priority, Date startdate, Integer taskindex,
              String taskname) {
          this.depth = depth;
          this.duration = duration;
          this.durationunit = durationunit;
          this.enddate = enddate;
          this.parentid = parentid;
          this.percentdone = percentdone;
          this.priority = priority;
          this.startdate = startdate;
          this.taskindex = taskindex;
          this.taskname = taskname;
      }
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      @Column(name = "taskid", unique = true, nullable = false)
      public Integer getTaskid() {
          return taskid;
      }
  
      public void setTaskid(Integer taskid) {
          this.taskid = taskid;
      }
  
      @Column(name = "depth")
      public Integer getDepth() {
          return depth;
      }
  
      public void setDepth(Integer depth) {
          this.depth = depth;
      }
  
      @Column(name = "duration", precision = 22, scale = 0)
      public Double getDuration() {
          return duration;
      }
  
      public void setDuration(Double duration) {
          this.duration = duration;
      }
  
      @Column(name = "durationunit")
      public String getDurationunit() {
          return durationunit;
      }
  
      public void setDurationunit(String durationunit) {
          this.durationunit = durationunit;
      }
  
      @Temporal(TemporalType.TIMESTAMP)
      @Column(name = "enddate", length = 19)
      public Date getEnddate() {
          return enddate;
      }
  
      public void setEnddate(Date enddate) {
          this.enddate = enddate;
      }
  
      @Column(name = "parentid")
      public Integer getParentid() {
          return parentid;
      }
  
      public void setParentid(Integer parentid) {
          this.parentid = parentid;
      }
  
      @Column(name = "percentdone")   
      public Integer getPercentdone() {
          return percentdone;
      }
  
      public void setPercentdone(Integer percentdone) {
          this.percentdone = percentdone;
      }
  
      @Column(name = "priority")
      public Integer getPriority() {
          return priority;
      }
  
      public void setPriority(Integer priority) {
          this.priority = priority;
      }
  
      @Temporal(TemporalType.TIMESTAMP)
      @Column(name = "startdate", length = 19)
      public Date getStartdate() {
          return startdate;
      }
  
      public void setStartdate(Date startdate) {
          this.startdate = startdate;
      }
  
      @Column(name = "taskindex")
      public Integer getTaskindex() {
          return taskindex;
      }
  
      public void setTaskindex(Integer taskindex) {
          this.taskindex = taskindex;
      }
  
      @Column(name = "taskname")
      public String getTaskname() {
          return taskname;
      }
  
      public void setTaskname(String taskname) {
          this.taskname = taskname;
      }
  
  
  }
  </code></pre>
  
  <p><strong>the project pojo is associated with task as one-to-many relationship</strong>. Now I want to delete one task based on the id I am passing,
   but the problem is that I am not able to delete the foreign key of the join table project_task.</p>
  
  <p>I tried below code to delete the project_task first</p>
  
  <pre><code>Session session = this.hibernateTemplate.getSessionFactory().getCurrentSession();
          Query query = session.createQuery("delete from project_task where taskid="+id);
          query.executeUpdate();
  </code></pre>
  
  <p>and then tried to delete the task with below code</p>
  
  <pre><code>Object record = hibernateTemplate.load(Task.class, id);
  hibernateTemplate.delete(record);
  </code></pre>
  
  <p>but don't know why delete is not happening here. Any one having idea what I am doing wrong in my code <strong>which doesn't allow the delete to be happened</strong></p>