Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7563551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:41:39+00:00 2026-05-30T13:41:39+00:00

forum member I need one help from you all. I am having two POJO

  • 0

forum member

I need one help from you all. I am having two POJO model with one to many relationship.
my project pojo is below

@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<Task> tasks = new HashSet<Task>(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<Task> 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<Task> getTasks() {
        return tasks;
    }

    public void setTasks(Set<Task> tasks) {
        this.tasks = tasks;
    }


}

and my task pojo is

@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;
    }


}

the project pojo is associated with task as one-to-many relationship. 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.

I tried below code to delete the project_task first

Session session = this.hibernateTemplate.getSessionFactory().getCurrentSession();
        Query query = session.createQuery("delete from project_task where taskid="+id);
        query.executeUpdate();

and then tried to delete the task with below code

Object record = hibernateTemplate.load(Task.class, id);
hibernateTemplate.delete(record);

but don’t know why delete is not happening here. Any one having idea what I am doing wrong in my code which doesn’t allow the delete to be happened

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:41:40+00:00Added an answer on May 30, 2026 at 1:41 pm

    Try breaking the association first:

    Task record = hibernateTemplate.load(Task.class, id);
    Project project = hibernateTemplate.load(Project.class, projectId);
    project.getTasks().remove(record);
    hibernateTemplate.update(project);
    hibernateTemplate.delete(record);
    

    If you don’t have the project id available, you might want to create an inverse ManyToOne relationship inside task.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi forum member I am having one problem with setting the radiofield in the
stackoverflow forum member I am having some problem with a certain report designed using
I need to help to show wall posts from the friends of the logged
I have two separate websites on the same server. One site is a forum
I need your help on one practical issue. I have created a WCF service
For a personal project, I need to build a forum using PHP and MySQL.
I am using sessions to pass user information from one page to another. However,
I'm trying to create an array of all .asm files I need to build
I want to crawl some data out of a phpBB forum i'm a member
There are times when we need a registered member on our website that allows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.