-->
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: Interceptor state changes not picked up by joined subclass
PostPosted: Sun Jan 02, 2011 9:35 pm 
Newbie

Joined: Tue Sep 02, 2003 10:35 pm
Posts: 9
Hullo, I've implemented an Interceptor to apply audit values (e.g. createdBy, createdDate). When a joined subclass entity is persisted the parent table record gets the audit values applied by the Interceptor but the child table record does not and in my case a not-null integrity constraint violation occurs. If I set the audit fields on the entity object before persisting, effectively bypassing the Interceptor, both parent and child records get the audit fields correctly.

Looking at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(...) there is the following comment and code before the Interceptor is called:
Code:
      // Put a placeholder in entries, so we don't recurse back and try to save() the
      // same object again. QUESTION: should this be done before onSave() is called?
      // likewise, should it be done before onUpdate()?
      source.getPersistenceContext().addEntry(
            entity,
            Status.SAVING,
            null,
            null,
            id,
            null,
            LockMode.WRITE,
            useIdentityColumn,
            persister,
            false,
            false
      );


This looks related to my problem but I don't understand enough of the internal logic to be sure. It does suggest that the logic could be reordered which could mean the audit values applied by the Interceptor are done before the parent and child table record values are assigned.

Here are my hibernate definitions:
Code:
   <class name="EntityA" table="EntityA">
      <id name="id" column="ID">
         <generator class="native"/>
      </id>
   
      <!-- Properties -->
      
      <!-- VxsAuditable attributes -->
      <property name="createdBy" column="CREATED_BY_USER" update="false"/>
      <property name="createdTimestamp" column="CREATED_TIMESTAMP" update="false"/>
      <property name="updatedBy" column="UPDATED_BY_USER" insert="false"/>
      <property name="updatedTimestamp" column="UPDATED_TIMESTAMP" insert="false" update="false"/>
   </class>

   <joined-subclass name="EntityB" extends="EntityA" table="EntityB">
      <key column="ID"/>
       
      <!-- Properties -->
       
      <!-- VxsAuditable attributes -->
      <property name="createdBy" column="CREATED_BY_USER" update="false"/>
      <property name="createdTimestamp" column="CREATED_TIMESTAMP" update="false"/>
      <property name="updatedBy" column="UPDATED_BY_USER" insert="false"/>
      <property name="updatedTimestamp" column="UPDATED_TIMESTAMP" insert="false" update="false"/>
   </joined-subclass>


Does anyone have any idea whether I'm doing something wrong or possible there could be a bug? Cheers


Top
 Profile  
 
 Post subject: Re: Interceptor state changes not picked up by joined subclass
PostPosted: Sun Jan 02, 2011 9:42 pm 
Newbie

Joined: Tue Sep 02, 2003 10:35 pm
Posts: 9
Forgot to mention that I'm using Hibernate v3.5.6-Final against MySQL v5.1.38 and this is the integrity contraint violation exception on the child record insert:
Code:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'CREATED_BY_USER' cannot be null
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
   at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
   at com.mysql.jdbc.Util.getInstance(Util.java:382)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1039)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3593)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2111)
   at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2407)
   at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2325)
   at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2310)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2421)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2838)
   at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:267)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
   at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
   at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
   at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
   at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:800)
   at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:774)
   at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:778)


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.