[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1661) merge of a deleted object results in a insert?

Emmanuel Bernard (JIRA) noreply at atlassian.com
Thu May 29 17:21:33 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30280 ] 

Emmanuel Bernard commented on HHH-1661:
---------------------------------------

Arthur Brown wrote:

ou argued that one ist don't know for *shure* that the state of "deleted" an entity realy "detached" is.

But it's definitly the case. I cannot understand why this bug is stil opened.

I took a look and debugged the stuff, an I have only to replace 2 lines of code (that was alread there), and voula, this behaive exactly as it schould.

Please could you consider this pacth and try to close this bug?

Old version

       if (result == null) {
           // TODO: we should throw an exception if we really *know* for sure
           // that this is a detached instance, rather than just assuming
           // throw new StaleObjectStateException(entityName, id);

           // we got here because we assumed that an instance
           // with an assigned id was detached, when it was
           // really persistent
           entityIsTransient(event, copyCache);
       }

New version

       if (result == null) {
           // TODO: we should throw an exception if we really *know* for sure
           // that this is a detached instance, rather than just assuming
           throw new StaleObjectStateException(entityName, id);

           // we got here because we assumed that an instance
           // with an assigned id was detached, when it was
           // really persistent
           // entityIsTransient(event, copyCache);
       }

For now, one could derive his own MergeListener from the dafualt one,
replace these lines and repalce the MergeListener in EventListsners.

I tested this, and it seems ok for me.

Regards
Arthur Brown



> merge of a deleted object results in a insert?
> ----------------------------------------------
>
>                 Key: HHH-1661
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1661
>             Project: Hibernate3
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.1.3
>         Environment: Hibernate 3.1.3, SQL Server
>            Reporter: Tu-Thach
>
> A persistent object is loaded from a session and deleted, then close the session.  Using that same object in another session and call merge results in the object being inserted into the database.  Here's the sample code:
> Session session = factory.getCurrentSession();
> session.beginTransaction();
> MyClass obj = (MyClass)session.load(MyClass.class, new Integer(10));
> session.delete(obj);
> session.getTransaction().commit();
> session = factory.getCurrentSession();
> session.beginTransaction();
> session.merge(obj);
> session.getTransaction().commit();
> Since the object is already deleted, merge could not find it and thus proceeds with a INSERT.  Shouldn't it throw an exception instead?

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list