Java Mailing List Archive

http://www.gg3721.com/

Home » users.openjpa »

Mapping of uni-directional 'shared' collection

Pinaki Poddar

2008-08-19


Author LoginPost Reply

An entity with two 'shared' collections i.e. member of the first collection
is a superset of the second collection. And I am mapping with a cross-table.
For example,

public class Question {
 @OneToMany
 private List<Choice> _choices;
 
 @OneToMany
 private List<Choice> _correctChoices;
}


If a Choice c belongs to _correctChoices, it must belong to _choices. That
is what I mean by _choices and _correctChoices are 'shared' collections.

The relationships are uni-directional i.e. Choice has no knowledge of
Question.

Now the mapping generates, as intended, a cross-table with three columns
QUESTION_ID, CHOICES_ID and CORRECTCHOICES_ID.
But during insert, two collections work independently so if I have a
Question (id=351) with 3 Choices (id=1,2,3) and correct choice is Choice 2,
then it inserts 4 rows
QUESTION_ID | CHOICES_ID | CORRECTCHOICES_ID
|      351   |       1     |         NULL |
|      351   |       2     |         NULL |
|      351   |       3     |         NULL |
|      351   |     NULL   |           2  | -- this one is
for the correct choice element

Is there a way to tell OpenJPA to use the same rows of _choices for elements
of _correctChoice?

--
Sent from the OpenJPA Users mailing list archive at Nabble.com.

©2008 gg3721.com - Jax Systems, LLC, U.S.A.