From: Vincent N. (JIRA) <no...@at...> - 2006-06-12 04:11:32
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1661?page=comments#action_23317 ] Vincent Ngan commented on HHH-1661: ----------------------------------- Can anyone tell me why this is the expected behavior? I think it breaks optimistic concurrency protection. If the merge() method is able to detect an optimistic concurrency problem when a detached object has been updated by another transaction, it should also behave the same way if the object has been deleted by another transaction. Otherwise, the whole optimistic concurrency concept is broken. It is fine for the merge method to behave in this way if the object is not enabled with optimistic concurrency versioning, but if optimistic concurrency is enabled, it is definitely a bug or a design flaw in the merge method. > merge of a deleted object results in a insert? > ---------------------------------------------- > > Key: HHH-1661 > URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1661 > Project: Hibernate3 > Type: Bug > Components: core > 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 |