Announcement Announcement Module
No announcement yet.
How does CascadeType.All work under the covers Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How does CascadeType.All work under the covers

    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:

    call the parentEnity_roo.aj method persist() this will then call a aspect which will populate the parentId
    Then call the childEntity_roo.aj method persist()

    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