50 likes | 85 Views
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.
E N D
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
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.
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); } }
@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/
Thank You!! Call us: 70-70-90-50-90 www.ducatindia.com