InterviewSolution
| 1. |
Look at the highlighted line in the below code and explain its meaning: |
|
Answer» The highlighted line defines “CASCADE=Cascade Type.ALL” and it essentially means that any change that happens to Employee ENTITY must cascade to all associated entities (Accounts Entity in this case) also. This means that if you save an employee into the database, then all associated accounts will also be saved into the database. If an Employee is DELETED, then all accounts associated with that Employee will also be deleted. But if we want to cascade only the save operation but not the delete operation, we need to clearly specify it USING below code. @OneToMany(cascade=CascadeType.PERSIST, fetch = FetchType.LAZY) @JoinColumn(name="EMPLOYEE_ID") private Set<AccountEntity> accounts;Now only when the save() or persist() methods are called using employee instance, will the accounts be persisted.If any other method is called on SESSION, its effect will not affect/cascade to the accounts entity. |
|