• Post Reply Bookmark Topic Watch Topic
  • New Topic

how does cascade work under the covers for parent child enity relationship  RSS feed

Tony Evans
Ranch Hand
Posts: 598
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a parent child relationship

Parent Entity Child Entity, when I persist the child enity I wish to persist the parent.


As you can guess when I call childEntity.persist() I get the id must be set for the parentEntity, before the childEnity can be persisted.

when I call childEnity.persist() I want hibernate to carry out the following actions:

parentEnity.persist() this will then call a aspect which will populate the parentId

In my childEnity i have the following relation ship set up

@ManyToOne(cascade = CascadeType.ALL, targetEntity = ParentEntity.class)
@JoinColumn(name="child_parent_id", referencedColumnName="parent_id")
private ParentEntity applicant;

As mentioned it does not work

Should calling childEntity.persist() then call the parentEntity.aj persist() method before it calls the childEntity.aj persist() method.

Or does calling childEntity.persist() only call childEntity.aj persist() and the parentEntity is persisted under the covers as part of the childEntity.persist() call.

If this is so then my aspect will never be called an I will need to rethink the logic.

Thanks for any help

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!