问题
what is the difference between owned one to many relationship and owned one to many bidirectional relationship i read the article below but i don't understand it. Article
回答1:
The owned one to many bidirectional relationship just means that the children have a reference to the parent. For example, the child below can access the parent via persistentUser. If persistentUser didn't exist in the PersistentLogin class then it would not be bidirectional.
One-to-Many (PersistentUser.java - Parent):
@OneToMany(mappedBy = "persistentUser", cascade = CascadeType.ALL)
private Collection<PersistentLogin> persistentLogins;
Many-to-One (PersistentLogin.java - Child):
@ManyToOne(fetch = FetchType.LAZY)
private PersistentUser persistentUser;
回答2:
Finally i understand it.Guess i have a Class Named FootBallTeam and it has a property named teamname. Now the pseudue code is
FootBallTeam ft = new FootBallTeam();
ft.setteamname("Barcelona");
then add 3 Player Class entity under this team named Messi,Xavi,Iniesta. now if the relationship is bidirectional when i run the code below,
ft.setteamname("Real Madrid");
it automatically runs the below codes behind the scenes.
Messi.setteamname("Real Madrid")
Xavi.setteamname("Real Madrid")
Iniesta.setteamname("Real Madrid")
来源:https://stackoverflow.com/questions/2981298/difference-between-owned-one-to-many-relationship-and-owned-one-to-many-bidirect