Difference between owned one to many relationship and owned one to many bidirectional relationship(Google App Engine Java Api)

回眸只為那壹抹淺笑 提交于 2019-12-12 11:07:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!