You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltaspike.apache.org by "Denis Falqueto (JIRA)" <ji...@apache.org> on 2014/10/29 17:44:34 UTC

[jira] [Comment Edited] (DELTASPIKE-701) Add method in EntityRepository to merge a detached entity and remove it

    [ https://issues.apache.org/jira/browse/DELTASPIKE-701?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14188547#comment-14188547 ] 

Denis Falqueto edited comment on DELTASPIKE-701 at 10/29/14 4:44 PM:
---------------------------------------------------------------------

I would like to propose a subtle change in the implementation:

public void attachAndRemove(Entity entity) {

    if (!entityManager.contains(entity)) {

        entity = entityManager.merge(entity);

    }

    entityManager.remove(entity);

}

It's just a simpler code path.


was (Author: denisfalqueto):
I would like to propose a subtle change in the implementation:

public void attachAndRemove(Entity entity) {
    // Entity is detached so perform a merge before removing.
    if (!entityManager.contains(entity))
        entity = entityManager.merge(entity);
    }
    entityManager.remove(entity);
}

It's just a simpler code path.

> Add method in EntityRepository to merge a detached entity and remove it
> -----------------------------------------------------------------------
>
>                 Key: DELTASPIKE-701
>                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-701
>             Project: DeltaSpike
>          Issue Type: Improvement
>          Components: Data-Module
>            Reporter: Juliano Marques
>            Assignee: Thomas Hug
>
> It will be nice if EntityRepository has a method like:
> public void attachAndRemove(Entity entity) {
>     if (entityManager.contains(entity)) {
>         entityManager.remove(entity);
>     } else {
>         entityManager.remove(entityManager.merge(entity));
>     }
> }
> This method will be useful to handle "java.lang.IllegalArgumentException: Removing a detached instance" exceptions.
> Workaround: Create a query delegate with this method.
> http://mail-archives.apache.org/mod_mbox/deltaspike-users/201408.mbox/%3CCAAuOd%3DXhb%3D-ssdzU%3DTdxWg8d18XXC15U7EjNiGya9eEgaA%2BUpA%40mail.gmail.com%3E



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)