views:

823

answers:

2

In this JPA example there is a code:

@OneToOne(cascade=CascadeType.ALL)
private Deity mother;

@OneToOne(cascade=CascadeType.ALL)
private Deity father;

@OneToMany(cascade=CascadeType.ALL)
private Set<Deity> children;

Why relation with father and mother is implemented by @OneToOne annotation and not in @ManyToOne relation? If Child and Parent will be separate classes Parent will have @OneToMany Collection<Child> children and Child have @ManyToOne Parent parent. This (deity) example seems reasonable but I looking for explanation why is that.

Links to JPA specification will be very appreciated.

+1  A: 

I think you are right, it is supposed to be ManyToOne relationship.

It must have been a mistake from the author of this code. Other parts of the code look suspicious also, I wouldn't trust it too much...


If you are looking for good persistence examples, I suggest the Hibernate documentation. Hibernate sticks with JPA as much as possible.

Note: You could switch your code to Hibernate, or stay with what you use and only use their documentation...

KLE
Well, it is example from OpenJPA - http://svn.apache.org/repos/asf/openjpa/tags/1.2.0/openjpa-examples/src/main/java/relations/ . So this example is bad to or this is relations on one entity special case.
cetnar
@cetnar Are you asking a question?
KLE
If this example is wrong, my question is invalid, but if it is correct I'm looking for explanation why is that.
cetnar
@cetnar OK, I understand :-) **I believe the OneToOne example is wrong**, and also other parts of the example seem questionable, so I answered this way. You can trust this opinion or not, it is up to you ;-)
KLE
+1  A: 

I am not sure but the example in site could refer to a person who has 1 mother and 1 father(hence unique one to one relation) and many children (one to many relation).

This example might be just to show that relations.

PS: i really am not sure, but then this is what occured to me..

Richie