Supposing I have two entities a parent object and a child. I want the child to have a relationship specified to the parent entity and a reference, but I don't want the parent to have to know about it. The reason for this is there are numerous such relationships and explicitly specifying the relationship for all these children will mean continually updating and polluting the parent objects. However I still want deletes of the parent object to cascade to the child. As an additional constraint the child object only ever has the reference to the parent entity set by setting an attribute that references the parent's ID. Supposing I have something like:
@Entity
class Child {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@Column(nullable=false)
private Long parentId;
@ManyToOne(fetch=FetchType.LAZY, optional=false)
@JoinColumn(name="parentId", insertable=false, updatable=false, nullable=false, unique=false)
private Parent parentEntity;
// etc...
}
@Entity
class Parent {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
// etc...
}
Then is there any way that deletes of the parent object can be cascaded to the child without adding an additional relationship to the parent entity?
A solution that uses only JPA annotations would be preferred, but any help would be appreciated.