Saved Bookmarks
| 1. |
@Entity @Table(name = "Employee") public class EmployeeEntity implements Serializable { private static final long serialVersionUID = -1798070786993154676L; @Id @Column(name = "ID", unique = true, nullable = false) privateInteger employeeId; @Column(name = "FIRST_NAME", unique = false, nullable = false, length = 100) private String firstName; @Column(name = "LAST_NAME", unique = false, nullable = false, length = 100) private String lastName; @OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY) `(name="EMPLOYEE_ID") private Set<AccountEntity> accounts; //Getters and Setters |
|
Answer» One of the main aspects of JPA is that it helps to propagate PARENT to Child RELATIONSHIPS. This behavior is possible through CascadeTypes. The CascadeTypes supported by JPA are:
The cascade configuration OPTION accepts an array of CascadeTypes. The below example shows how to add the refresh and merge operations in the cascade operations for a One-to-Many relationship: @OneToMany(cascade={CascadeType.REFRESH, CascadeType.MERGE}, fetch = FetchType.LAZY) @JoinColumn(name="EMPLOYEE_ID") private Set<AccountEntity> accounts;Cascading is USEFUL only for Parent - Child associations where the parent entity state transitions cascade to the child entity. |
|