1 / 5

JPA and Hibernate Cascade Types

JPA allows you to propagate the state transition from a parent entity to a child. For this purpose, the JPA javax.persistence.CascadeType defines various cascade types:<br><br>ALL u2013 cascades all entity state transitions<br>PERSIST u2013 cascades the entity persist operation.<br>MERGE u2013 cascades the entity merge operation.<br>REMOVE u2013 cascades the entity remove operation.<br>REFRESH u2013 cascades the entity refresh operation.<br>DETACH u2013 cascades the entity detach operation.

Ducat1
Télécharger la présentation

JPA and Hibernate Cascade Types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Welcome toDucat India Language | Industrial Training | Digital Marketing | Web Technology | Testing+ | Database | Networking | Mobile Application | ERP | Graphic | Big Data | Cloud Computing Apply Now Training & Certification Call us: 70-70-90-50-90

  2. JPA and Hibernate Cascade Types • JPA allows you to propagate the state transition from a parent entity to a child. For this purpose, the JPA javax.persistence.CascadeType defines various cascade types: • ALL – cascades all entity state transitions • PERSIST – cascades the entity persist operation. • MERGE – cascades the entity merge operation. • REMOVE – cascades the entity remove operation. • REFRESH – cascades the entity refresh operation. • DETACH – cascades the entity detach operation. • Additionally, the CascadeType.ALL will propagate any Hibernate-specific operation, which is defined by the org.hibernate.annotations.CascadeTypeenum: • SAVE_UPDATE – cascades the entity saveOrUpdate operation. • REPLICATE – cascades the entity replicate operation. • LOCK – cascades the entity lock operation. • Cascading only makes sense only for Parent-Child associations (the Parent entity state transition being cascaded to its Child entities). Cascading from Child to Parent is not very useful and usually, it’s a mapping code smell.

  3. Then name is enough The following examples will explain some of the aforementioned cascade operations using the following entities: @Entity publicclassPerson { @Id privateLong id; privateString name; @OneToMany(mappedBy="owner", cascade=CascadeType.ALL) privateList< Phone> phones =newArrayList<> (); //Getters and setters are omitted for brevity publicvoidaddPhone(Phonephone) { this.phones.add(phone); phone.setOwner(this); } }

  4. @Entity publicclassPhone { @Id privateLong id; @Column(name="`number`") privateString number; @ManyToOne(fetch=FetchType.LAZY) privatePerson owner; //Getters and setters are omitted for brevity } Read More: https://tutorials.ducatindia.com/java/jpa-and-hibernate-cascade-types/

  5. Thank You!! Call us: 70-70-90-50-90 www.ducatindia.com

More Related