vijay
vijay

Reputation: 11

How to make ondelete cascade in hibernate with annotation

I would like to make ondelete cascade in hibernate with annotation. In my POJO class I have properties like id(Long),Module module and key as string properties. I would like to introduce cascade on deleting the key as PK an it having the FK relation-ship table labelText.

please find below code.

@Entity
@Table(name = "tLabel")
@SuppressWarnings("serial")
public class Label {
    private long id;
    private ModuleImpl module;
    private String key;
}

all properties having the setters and getters.

How to introduce ondelete cascade?

Upvotes: 0

Views: 97

Answers (1)

Scary Wombat
Scary Wombat

Reputation: 44854

So in you example you have a one to one relationship between Label and Module. Sorry can not quite follow your explanation, but I hope you get the idea

So you will to annotate with

@OneToOne (cascade=CascadeType.REMOVE)
private ModuleImpl module;

Upvotes: 1

Related Questions