-->
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.  [ 3 posts ] 
Author Message
 Post subject: Audit Interceptor bug or expected behaviour
PostPosted: Sun Mar 26, 2006 2:16 am 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
Hi,

I'm using a session interceptor to detect inserts and updates.
When one occurs I do set the dateCreated and dateModified of the entity if the entity is auditable.

Here's the onSave method

Code:
  public boolean onSave( Object entity, Serializable id, Object[] currentState, String[] propertyNames, Type[] types  )
    throws CallbackException
    {
        boolean returnValue = false;
        if ( entity instanceof HibernateAuditableEntity )
        {
           
            HibernateAuditableEntity hae  = (HibernateAuditableEntity)entity;
            hae.setDateCreated( new Timestamp( System.currentTimeMillis() ) );
            //returnValue = true;
        }
        return returnValue;
    }


similarly for onFlushDirty()


This approach works great for entities that have no collection ( one to many relationship) .

I stepped into Hibernate code and it seems that for entities with collections there is a forced substitution

Here the code from AbstractSaveEventListener.java

Code:

   protected Serializable performSaveOrReplicate(
         Object entity,
         EntityKey key,
         EntityPersister persister,
         boolean useIdentityColumn,
         Object anything,
         EventSource source)
   throws HibernateException {
   
   {
   
   ....
   

      boolean substitute = substituteValuesIfNecessary(entity, id, values, persister, source);

      if ( persister.hasCollections() ) {
         substitute = substitute || visitCollectionsBeforeSave(id, values, types, source);
      }

      if (substitute) persister.setPropertyValues( entity, values, source.getEntityMode() );


My interceptor is called in the substituteValuesIfNecessary method() and I do return false in onSave. Since the persistor detects that there is a collection in the current entity it calles visitCollectionBeforeSave that returns true and forces an override of the just set dateCreated with a null.

The collection is defined as below in the entity mapping
Code:
        <set name="roles" cascade="all" inverse="true" lazy="true" >
           <key column="PARTICIPANT_ID" />
         <one-to-many class="Role" />
      </set>   


Is this the expected behaviour and how can I bypass this annoyance ?
BTW this happens only when I do inserts with entities that have list(s).

Regards,
Q


Top
 Profile  
 
 Post subject: No one ?
PostPosted: Tue Mar 28, 2006 2:03 am 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
Any idea will be appreciated!


Top
 Profile  
 
 Post subject: Bug
PostPosted: Wed Apr 05, 2006 2:10 pm 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
Should I submit this as a bug ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.