[
https://issues.apache.org/jira/browse/OPENJPA-2239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13422335#comment-13422335
]
Vermeulen commented on OPENJPA-2239:
------------------------------------
Personally I would really have liked an exception to be thrown. But if that is
not acceptable a warning would be nice. The problem here is that the entity
looks like it is a perfectly valid and it even works perfectly valid until you
remove something and see it disappear in the other list.
I normally let JPA generate the database schema and use the minimum amount of
annotations necessary. Usually I use either mappedBy= or @JoinColumn but here I
decided to let JPA figure out what to do in this (for me) unusual situation of
two separate relationships between the same tables. It seemed to come up with a
working solution so I thought "hey why not, this kind of join table probably
works as well". I really cannot see how I should have had the knowledge that
this was not going to work as expected, especially because I let JPA figure out
itself what to do.
I do agree that using two join tables or join columns is a better separation of
concerns. This could be done by default by JPA if it generated different join
table names for different fields but I can see that this change won't happen.
> removing from one List<X> removes all from other List<X> in same entity
> -----------------------------------------------------------------------
>
> Key: OPENJPA-2239
> URL: https://issues.apache.org/jira/browse/OPENJPA-2239
> Project: OpenJPA
> Issue Type: Bug
> Components: kernel
> Affects Versions: 2.1.1
> Reporter: Vermeulen
> Attachments: Order.java, OrderLine.java, OrderLineRemovalBugTest.java
>
>
> I have an Order entity that has two separate lists of OrderLine entities:
> ...
> @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
> private List<OrderLine> plannedOrderLines = new ArrayList<OrderLine>();
> @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
> private List<OrderLine> actualOrderLines = new ArrayList<OrderLine>();
> ...
> I remove a single element from actualOrderLines, then merge the entity and
> close the entity manager. When I find the entity again with a different
> entity manager, the plannedOrderLines list is empty.
> OpenJPA generates one join table that contains entries for both lists. I used
> this configuration for a long time and it seems to work fine except for this
> bug. I verified in the database that the entries for planned order lines are
> all removed from the join table.
> Workaround: use @JoinTable or @JoinColumn annotation so that both lists do
> not map to the same join table.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira