We help IT Professionals succeed at work.
Get Started

How to delete rows with forign key while deleting only the top level row in hibernate

Rohit Bajaj
Rohit Bajaj asked
on
171 Views
Last Modified: 2017-11-30
Hi,
I am using hibernate for persistence.
Here are the two classes which i am using as entities :

@Entity(name = "workflow_template")

public class WorkflowTemplate {

    
@Id
   
 @GeneratedValue(strategy = GenerationType.AUTO)
    
private Integer id;

    @OneToMany(cascade = {CascadeType.ALL})
    
@JoinColumn(name = "workflow_id")
    
@OrderColumn(name = "task_idx")
   
 private List<TaskTemplate> taskTemplates;

-----
@Entity(name = "task_template")

public class TaskTemplate {

    
@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
  
  private Integer id;

    
@ManyToOne
    @JoinColumn(name = "workflow_id", nullable = false)
    
private WorkflowTemplate workflowTemplate;


Open in new window


Now for deletion of the workFlowTemplate row i first need to delete the task template row and then delete the workflow_template row.
Is there a way where i could just specify delete the workflowTemplate row and it automatically deletes all the rest of such things which have a join in them.
Comment
Watch Question
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 2 Answers and 2 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE