hibernate-envers

Creating Envers custom revision entity

孤街浪徒 提交于 2019-12-05 05:12:45
I'm trying to setup audit for our project. I started from the default configuration which works fine. The next step is to store the user which has made changes. Following the manual I created custom entity revision: package com.csbi.samples.utils.audit; import java.io.Serializable; import java.text.DateFormat; import java.util.Date; import org.hibernate.envers.RevisionNumber; import org.hibernate.envers.RevisionTimestamp; import org.hibernate.envers.RevisionEntity; import javax.persistence.Id; import javax.persistence.GeneratedValue; import javax.persistence.Entity; import javax.persistence

How to delete entries from my audit table?

本小妞迷上赌 提交于 2019-12-05 04:54:19
I am currently working with Hibernate Envers. How to delete entries in the audit table related to the entity I want to delete? My entity has no relation with other entities. I figured out that I have to do that in onPostDelete method of my custom listener: import org.hibernate.envers.event.AuditEventListener; import org.hibernate.event.PostCollectionRecreateEvent; import org.hibernate.event.PostDeleteEvent; import org.hibernate.event.PostInsertEvent; import org.hibernate.event.PostUpdateEvent; import org.hibernate.event.PreCollectionRemoveEvent; import org.hibernate.event

How not to audit a join table and related entities using Hibernate Envers?

邮差的信 提交于 2019-12-04 15:33:34
问题 I use Hibernate Envers to audit my entities. I have one audited entity, Foo , which has a List<Bar> as properties. However, I don't want to audit the Bar entities. Thus, I wrote that: @Entity @Audited public class Foo { @JoinTable(name = "T_FOO_BAR", joinColumns = @JoinColumn(name = "FOO_ID"), inverseJoinColumns = @JoinColumn(name = "BAR_ID")) @ManyToMany(cascade = PERSIST) @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) public List<Bar> getBars() { return bars; } } Now, I

Why Hibernate Envers is ignoring my custom RevisionEntity?

╄→гoц情女王★ 提交于 2019-12-04 13:11:43
I'm developing an application using JPA 2.1 (supported by hibernate 4.2.11) with spring 4.0.2. We are using Envers for auditing changes in project entities. That is working fine. The problem comes when we try to use custom Revision Entity as Envers documentation says: http://docs.jboss.org/hibernate/core/4.1/devguide/en-US/html/ch15.html#envers-revisionlog We have made a custom class and a custom listener as pointed in the documentation but it seems that they are totally ignored by Hibernate. The custom classes: @Entity @RevisionEntity(AuditingRevisionListener.class) public class

Audit ManyToMany Relationships using Hibernate Envers

夙愿已清 提交于 2019-12-04 10:35:47
I'm using Hibernate Envers in order to audit my entities. But I have a problem. I want to audit an Entity that have a ManyToMany relationship. I found that exists an @AuditJoinTable but I don't have idea how it works. Can someone giveme an example? Auditing many-to-many relations should work without any additional configuration, provided that both sides of the relation are audited. As to @AuditJoinTable , the annotation is used to specify a custom table name of the join table. See: http://docs.jboss.org/hibernate/orm/4.1/javadocs/org/hibernate/envers/AuditJoinTable.html The default name is

What's the difference between @NotAudited and RelationTargetAuditMode.NOT_AUDITED in Hibernate EnVers?

落花浮王杯 提交于 2019-12-04 07:38:36
问题 @NotAudited @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) @OneToMany(mappedBy = "booking") @OrderBy("bookingOrder") private List<CustomerBooking> customerBookingList = new LinkedList<CustomerBooking>(); Why use both? is it good to use both or would one suffice? 回答1: Use NotAudited on fields when you don't want the value / relationship to be audited at all. I believe you can use this on a field with or without a relationship such as OneToMany, ManyToMany, or just Column. Use

jboss 7 (envers 4) Unable to load class org.hibernate.envers.event.AuditEventListener

倾然丶 夕夏残阳落幕 提交于 2019-12-04 07:31:23
I port from hibernate Envers 3.6 to Envers 4.0. This new version doesn't have AuditEventListener . Old version requires: listeners I can't find how to configure the new version. user613465 In version 4.0 : <properties> <property name="hibernate.ejb.event.post-insert" value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener" /> <property name="hibernate.ejb.event.post-update" value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener" /> <property name="hibernate.ejb.event.post-delete" value="org

Envers: Unidirectional OneToMany without additional audit table?

假装没事ソ 提交于 2019-12-04 05:25:13
The following database schema: Employee[EMP_ID (PK), name, salary] Phone[ID (PK), number_str, OWNER_ID (FK)] Employee_aud[EMP_ID (PK), REV (PK/FK), REVTYPE, name, salary] Phone_aud[ID (PK), REV (PK/FK), REVTYPE, number_str] Employe_phone_aud[REV(PK/FK), OWNER_ID(PK/FK), REVTYPE(PK/FK)] can be expressed with the following Java Entities: Employee : @Entity @Audited public class Employee { @Id @GeneratedValue @Column(name = "EMP_ID") private long id; @Column private String name; @Column private int salary; @OneToMany @JoinColumn(name = "OWNER_ID", referencedColumnName = "EMP_ID") private final

envers multi level entity revision howto

女生的网名这么多〃 提交于 2019-12-04 05:17:55
User have n Contacts. A Contact can have a localized Comment (Comments are shared between Contacts). Java Beans: @Audited @Entity public class User { @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) Set<Context> contacts; } @Audited @Entity public class Contact { @ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}) Comment comment; } @Audited @Entity public class Comment { String de; String en; String fr; } If I change the german localization (Comment.de) of a contact (Contact.comment) then this will

spring-data-envers Hibernate java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionImplementor.getTransactionCoordinator

早过忘川 提交于 2019-12-04 04:31:07
问题 I have a Spring boot 1.4.2 application with Hibernate 5.2.2 and Spring data Envers 1.0.5. Entities are persisted fine when they are not audited. Annotating the entities with @Audited results in a transaction rollback with the following stacktrace. Any ideas? > 2016-12-22 18:15:08,364 ERROR | http-nio-8080-exec-1 | > org.springframework.orm.jpa.JpaTransactionManager | Commit > exception overridden by rollback exception > java.lang.NoSuchMethodError: > org.hibernate.engine.spi