Delete ObjectDetails from Object Spring Data

80 views Asked by At

I have the following AnyObject. If I set details to this object all works fine. But if i try to delete the details, I'm able to set the details to null. But the details entry in database is not deleted.

Somebody can tell me why?
Thank you. :-)

@Entity
@Table(name="ANY_OBJECT")
public class AnyObjects extends Abstract Entity{
    private String anyProp;
    private AnyObjectDetails details;
    //Getter
    @ManyToOne(cascade=CascadeType.PERSIST)
    @JoinColumn(name="DETAILS_ID")
    public AnyObjectsDetails getDetails(){
        return details;
    }
    //...
}

public class AnyObjectController{
    //...
    anyObjectDetailsRepository.delete(anyObject.getDetails());
    anyObject.setDetails(null);
    //...
}
1

There are 1 answers

0
Abhijeet On

Please check the Documentation here. you may want to change the CascadeType to CascadeType.ALL. This should work.