Hi everybody!
I have the next hibernate-conf:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/terceros" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>es.tragsatec.ws.admin.vo.Country</value>
<value>es.tragsatec.ws.admin.vo.Municipality</value>
<value>es.tragsatec.ws.admin.vo.PhoneType</value>
<value>es.tragsatec.ws.admin.vo.Province</value>
<value>es.tragsatec.ws.admin.vo.StreetType</value>
<value>es.tragsatec.ws.admin.vo.IdentificationCardType</value>
<value>es.tragsatec.ws.admin.vo.LegalStatus</value>
<value>es.tragsatec.ws.admin.vo.Bank</value>
</list>
</property>
<property name="namingStrategy">
<ref bean="namingStrategy" />
</property>
<property name="eventListeners">
<map>
<entry key="post-update">
<bean class="org.hibernate.envers.event.AuditEventListener"></bean>
</entry>
<entry key="post-insert">
<bean class="org.hibernate.envers.event.AuditEventListener"></bean>
</entry>
<entry key="post-delete">
<bean class="org.hibernate.envers.event.AuditEventListener"></bean>
</entry>
</map>
</property>
<property name="hibernateProperties">
<props>
<!-- MYSQL -->
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.search.default.directory_provider">
org.hibernate.search.store.FSDirectoryProvider
</prop>
<prop key="hibernate.search.default.indexBase">c:\temp\sgt\index\</prop>
</props>
</property>
</bean>
</beans>
I also have these dependencies:
Code:
<dependency>
<groupId>org.jboss.envers</groupId>
<artifactId>jboss-envers</artifactId>
<version>1.2.2.GA</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
With this stuff the envers project works ok. But I have the same problem as puneetswarup (java.lang.ArrayStoreException) if I declare a listener make of my own:
Code:
package es.tragsatec.ait.oviedo.audit;
import org.hibernate.envers.RevisionListener;
import org.springframework.security.Authentication;
import org.springframework.security.context.SecurityContextHolder;
public class AuditRevisionListener implements RevisionListener {
public void newRevision(Object revisionEntity) {
AuditRevisionEntity are = (AuditRevisionEntity) revisionEntity;
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
are.setUsername(authentication.getName());
}
}
And the code of the RevisionEntity:
Code:
@Entity
@RevisionEntity(AuditRevisionListener.class)
public class AuditRevisionEntity {
@Id
@GeneratedValue
@RevisionNumber
private int id;
@RevisionTimestamp
private long timestamp;
private String username;
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
@Transient
public Date getDate() {
return new Date(this.getTimestamp());
}
.../...
Any idea?
Thanks in advance,
Luis