You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Vermeulen (JIRA)" <ji...@apache.org> on 2012/07/24 10:34:34 UTC

[jira] [Created] (OPENJPA-2239) removing from one List removes all from other List in same entity

Vermeulen created OPENJPA-2239:
----------------------------------

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


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

        

[jira] [Commented] (OPENJPA-2239) removing from one List removes all from other List in same entity

Posted by "Vermeulen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13422336#comment-13422336 ] 

Vermeulen commented on OPENJPA-2239:
------------------------------------

By the way, my colleague had already noticed that JPA generated a single join table and he also didn't anticipate that this was going to give this bug.
                
> 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

        

[jira] [Commented] (OPENJPA-2239) removing from one List removes all from other List in same entity

Posted by "Vermeulen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13421266#comment-13421266 ] 

Vermeulen commented on OPENJPA-2239:
------------------------------------

Note that OPENJPA-1435 (which is already resolved) is a different one but may be related because it also has an entity with two collections of the same type.
                
> 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
>
> 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

        

[jira] [Commented] (OPENJPA-2239) removing from one List removes all from other List in same entity

Posted by "Vermeulen (JIRA)" <ji...@apache.org>.
    [ 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

        

[jira] [Updated] (OPENJPA-2239) removing from one List removes all from other List in same entity

Posted by "Vermeulen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-2239?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Vermeulen updated OPENJPA-2239:
-------------------------------

    Attachment: OrderLineRemovalBugTest.java
                OrderLine.java
                Order.java

Entities and test case which show the bug.
                
> 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

        

[jira] [Commented] (OPENJPA-2239) removing from one List removes all from other List in same entity

Posted by "Vermeulen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13460546#comment-13460546 ] 

Vermeulen commented on OPENJPA-2239:
------------------------------------

I had another occurence of this bug which is even more subtle to find. My Appointment entity extends the Booking entity which has a list of rooms in which the appointment takes place. The Appointment entity has a different list of rooms to visit (as a tour). The subclass has to specify a different join table otherwise this bug appears.
                
> 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
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (OPENJPA-2239) removing from one List removes all from other List in same entity

Posted by "Kevin Sutter (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13422390#comment-13422390 ] 

Kevin Sutter commented on OPENJPA-2239:
---------------------------------------

Thanks for the background and insights.  Issuing a warning might be a good way to go.  Based on the comments from you and your colleague, I can understand why "something" needs to be done.  There are too many assumptions being made and when some action breaks one of those assumptions, the outcome is not discernable.  OpenJPA needs to do something with this type of scenario.  Thanks for the comments and the testcase for reproducing it.
                
> 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

        

[jira] [Commented] (OPENJPA-2239) removing from one List removes all from other List in same entity

Posted by "Kevin Sutter (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13421493#comment-13421493 ] 

Kevin Sutter commented on OPENJPA-2239:
---------------------------------------

Although I can understand the problem you are describing, isn't the proper solution to define the alternate join table as you suggested?  If you want to maintain two separate relationships between two entitiy types, you need the ability to separate those concerns.  By default, JPA will utilize the same join table and join columns based on the entity names and definitions.  So, if you need to maintain two separate relationships, you'll need two separate join tables.

Or, to put it another way, how would you expect OpenJPA's behavior to change for this scenario?  Issue a warning that the same table is being utilized?  Throwing an exception wouldn't be good since there may be scenarios where defining two relationships is a valid operation.  Automatically synch up the plannedOrderLines and actualOrderLines?  But, that isn't what you would expect either.

Not sure what your expectations are with this JIRA.  Thanks.
                
> 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