I am new to Hibernate. I had read that when using cascade.ALL to persist, changes are propogated from the owning side. I have below example where I am saving the non owning entity and the owning entity is also saved.
class Account {
@OneToMany(mappedBy="account" , cascade=CascadeType.ALL)
List<Transaction> list= new ArrayList<Transaction>();
}
class Transaction {
@ManyToOne
@JoinColumn(name="account_id")
Account account;
}
Account a = new Account("savings");
Transaction t1 = new Transaction("shoe purchase", 45);
t1.setAccount(a);
a.getList().add(t1);
accountRepository.save(a); //If cascaded is on account
Does it matter which side cascade is on. In this case I could have used cascade.PERSIST
Another question I had was do we write unidirectional mapping for OneToMany/ManyToOne relationships ?
Thank you