views:

34

answers:

2

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  A: 

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;
Taylor Leese
Hi taylor thanks for the reply.I'm new to GAE so i may understand it a little hard.Now guess there is a FootballTeam.java class and a Player.java class.A Football team have many Players.Now what happens if i do this relationship bidirectional ?
Kerem Pekçabuk
That relationship would be represented the same way as the example I gave. The @OneToMany relationship would be on the FootballTeam class with a Collection<Player> players attribute. The @ManyToOne relationship would be in the Player class with a FootballTeam team attribute.
Taylor Leese
Taylor i understood that but i think i don't know the meaning of the word bidirectional in relationships.What happens if the relation becomes bidirectional ? could you please give me an example about football team class and player class ? Thanks
Kerem Pekçabuk
The term bidirectional just means that the player has a reference to the team. If this relationship does not exist on the player then it is not bidirectional. Rather, it would be a unidirectional relationship.
Taylor Leese
An owned one to many relationship means that every record must have a referance.For example every player must have a team.It looks like the same thing in your answer.i couldn't understand the difference between an owned relationship and bidirectional relationship.
Kerem Pekçabuk
A: 

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")
Kerem Pekçabuk