-->
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: AuditLogInteceptor in Hibernate 4
PostPosted: Tue Jan 29, 2013 8:25 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Hi All,
Currently I am using Hibernate 4.0.1 and spring security 3.1.2 in my web application.
I would like to set create by and update by using Interceptor Hibernate

Code:
@Entity
class User {
...
}

@Entity
class Product implement AuditLog {
   public User getCreatedUser() {
      ...
   }
}

class AuditLogInterceptor extends EmptyInterceptor {
   public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames,
      Type[] types) {
      User user = userDao.getActiveUser();
      Date now = DateHelper.getCurrentDateTime();
      myentity.setCreatedBy(user);
      myentity.setCreatedDate(now);
      ...
   }
}

ApplicationContext.xml

<bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" id="sessionFactory"
    destroy-method="destroy">
    <property name="dataSource" ref="datasource" />
    <property name="packagesToScan">
      <list>
        <value>org.dolphin.entity</value>
      </list>
    </property>
    <property name="hibernateProperties">
      <props>
        <prop key="hibernate.dialect">${hibernate.dialect}</prop>
        <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
      </props>
    </property>
    <property name="entityInterceptor" ref="auditLogInterceptor" />
  </bean>


The problem is, in the auditLogInterceptor, I use userDao which need SessionFactory to be injected. So in this case, there is circular dependency. How to solve this issue?


Top
 Profile  
 
 Post subject: Re: AuditLogInteceptor in Hibernate 4
PostPosted: Fri Mar 01, 2013 1:54 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Hi All,

Is there any solution for this case?

Thanks


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.