Cascade Operations and Relationships in java

Chapter 6 - Java Persistence Entity Operations

    Cascade Operations and Relationships in java

  •           Entities relationships have dependencies on the existence of the other entity in the relationship.

    Example: A line item is part of an order; if the order is deleted, the line item also should be deleted. This is called a cascade delete relationship.

    Cascade Operation Description
    ALL All cascade operations will be applied to the parent entity’s related entity. All is equivalent to specifying cascade={DETACH, MERGE, PERSIST, REFRESH, REMOVE}
    DETACH If the parent entity is detached from the persistence context, the related entity will also be detached.
    MERGE If the parent entity is merged into the persistence context, the related entity will also be merged.

    Cascade Operation
    Description

    PERSIST
    If the parent entity is persisted into the persistence context, the related entity will also be persisted.
    REFRESH If the parent entity is refreshed in the current persistence context, the related entity will also be refreshed.
    REMOVE If the parent entity is removed from the current persistence context, the related entity will also be removed.

              Cascade delete relationships are specified using the cascade=REMOVE element specification for @OneToOne and @OneToMany relationships.

    Example:

    @OneToMany(cascade=REMOVE, mappedBy="customer")
    public Set getOrders() { return orders; } 

    Storing JPA Entity Objects

                   •  Explicit Persist

                   •  Referenced Embedded Objects

                   •  Referenced Entity Objects

                   •  Cascading Persist

                   •  Global Cascading Persist

                   •  Batch Store

© 2015 by Learncertification All Rights Reserved. The certification names are the trademarks of their respective owners. Terms & Privacy Policy