These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Update before Delete
PostPosted: Mon Nov 28, 2011 12:48 pm 
Newbie

Joined: Wed Jun 14, 2006 6:43 am
Posts: 4
We are getting an update when deleting an object. I can see it by turning the logging on for hibernate and there is always an update statement before the delete. Also seeing it from the database perspective.

So, does anyone know how and why hibernate would perform an update before a delete?

I completely isolated the code within a test, and only see the delete, no update. So it must be some configuration within the Web Application causing it.

The class mapping in question is also immutable (see below). The audit columns (see mapping) are assigned in an interceptor, but I changed this not to make any changes and makes no difference.

Code:
  <class name="org.....QueueVO" table="OPUS_QUEUES" lazy="false" mutable="false">
    <id name="queueId" type="java.lang.Long">
       <column name="OPQU_ID" precision="10" scale="0" />
       <generator class="sequence">
         <param name="sequence">OPQU_SEQ</param>
       </generator>
    </id>

    <!--  Audit Columns -->
    <version unsaved-value="negative" name="versionNumber" column="OPQU_VERSION_NUMBER" />
    <property update="false" name="createdDate" column="OPQU_CREATION_DATE" type="timestamp" />
    <property update="false" name="createdUser" column="OPQU_CREATION_USER" />
    <property name="updatedUser" column="OPQU_UPDATE_USER" />
    <property name="updatedDate" column="OPQU_UPDATE_DATE" type="timestamp" />
    <property name="sourceSystem" column="OPQU_SOURCE_SYSTEM" not-null="true"/>
   
    <property name="queueType" column="OPQU_QUEUE_TYPE" not-null="true"/>
    ...
    <property name="queueName" column="OPQU_QUEUE_NAME"  not-null="true"/>
  </class>


Any guidance on this will be appreciated, thanks


Top
 Profile  
 
 Post subject: Re: Update before Delete
PostPosted: Tue Nov 29, 2011 6:35 am 
Newbie

Joined: Wed Jun 14, 2006 6:43 am
Posts: 4
Ok, I have now managed to reproduce the problem in a very simple test.
To make things clearer, I have taken out all interceptors and event listeners.
And the test simply retrieves a row and then deletes it.

Now if the test is transactional, then the update occurs before the delete. But if non-transactional, then there is no update before the delete.

I think the difference here will be that when transaction the object is always associated to the hibernate session. But when non-transactional, the object is detached between the retrieve and the delete.

But why this makes a difference I do not know. So can anyone shed some light on this?

Code:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
@TransactionConfiguration(transactionManager="transactionManager")
@Transactional
public class TestHibAbcDAO
{
  @Test
  @Rollback(false)
  public void testRetrieveDelete()
  {
    SjeVO vo = abcDAO.retrieve(new Long(361463));
    abcDAO.delete(vo);
  }
}

new mapping
Code:
<?xml version="1.0" ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="org.....SjeVO" table="SJE_TEST" lazy="false" mutable="false">
    <id name="id" type="java.lang.Long">
      <column name="id" precision="10" scale="0" />
      <generator class="sequence">
        <param name="sequence">OPQU_SEQ</param>
      </generator>
    </id>

    <property name="name" column="name" not-null="true"/>
    <property name="something" column="SOMETHING" not-null="false"/>
  </class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.