-->
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.  [ 1 post ] 
Author Message
 Post subject: Getting only required value when we use event.geetOldState()
PostPosted: Mon Jan 03, 2011 3:57 am 
Newbie

Joined: Mon Jan 03, 2011 3:53 am
Posts: 3
Hi All,

I am using Hibernate 3 as my persistence framework.
Below is the sample hbm file I am using.

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="com.test.User" table="user">
          <meta attribute="implements">com.test.dao.interfaces.IEntity</meta>
          <id name="key" type="long" column="user_key">
                <generator class="increment" />
          </id>
         <property name="userName" column="user_name" not-null="true" type="string" />
         <property name="password" column="password" not-null="true" type="string" />
         <property name="firstName" column="first_name" not-null="true" type="string" />
        <property name="lastName" column="last_name" not-null="true" type="string" />
        <property name="createdDate" column="created_date" not-null="true" type="timestamp"     insert="false" update="false" />
       <property name="createdBy" column="created_by" not-null="true" type="string"  update="false" />
      </class>
    </hibernate-mapping>


I am added a post-update listener. What it will do is if there any updations perfomed on User then it will be invoked and cahnges will be inserted to audit table.


Below is the sample implementation for postupdate event.

Code:
public void onPostUpdate(PostUpdateEvent event)
    {
    LogHelper.info(logger, "Begin - onPostUpdate "
        + event.getEntity().getClass().getSimpleName());
    if (!this.checkForAudit(event.getEntity().getClass().getSimpleName()))
    {
     // check do we need to audit it.
    }

    // Get Attribute Names
    String[] attrNames = event.getPersister().getEntityMetamodel()
        .getPropertyNames();
    Object[] oldobjectValue = c
    Object[] newObjectValue = event.getState();

    this.auditDetailsEvent(attrNames, oldobjectValue, newObjectValue);
    LogHelper.info(logger, "End - onPostUpdate");
    // return false;
    }

Here is my requirement. event.getPersister().getEntityMetamodel()
.getPropertyNames(); or event.getOldState(); or event.getState();

must return attribute names or value which i can update or insert.

Is there any way to control the return values of above one's.

Can any one suggest me regarding this problem.

Thanks,
Narendra


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

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.