Say that I have 2 Entites of User and Message. User has a field called "messages" that has a list of messages and is annotated with "@manyToOne" and Message has a field called "owner" like the following:
User:
@Entity
Class User{
...
@OneToMany(mappedBy = "owner", cascade = CascadeType.ALL)
private List messages;
...}
Message:
@Entity
Class Message{
...
@ManyToOne(fetch = FetchType.LAZY)
private User owner;
...
}
My question - when adding a new message and setting the owner to be certain user, does the persistence knows to add another element to the User Object's "messages" list?
In other words: when creating a message and setting the "owner" - does the appropriate User "messages" list automatically increased by one?
- I'll be glad to see some code example. The web is full of complex examples that are hard to understand...