Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Tony Evans
Ranch Hand
Posts: 598
1
  • 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.

childEntity.persist()

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
childEntity.persist()

In my childEnity i have the following relation ship set up


@NotNull
@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



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic