hibernate-envers

Hibernate envers spring web app how to log username

半城伤御伤魂 提交于 2019-12-12 18:50:44
问题 I am using hiberbate 3.5 and spring 3.x I have envers working and the ... _aud and revinfo record are now being written. I now need to add the username to the audit record I'm guessing revinfo is the best place I have seen an example for seam app but nothing for spring app in jboss Can anyone help with this please. My main aim is to be able to record the windows authenticated user. 回答1: The Envers documentation has an answer for this if you use Seam. public class ExampleListener implements

envers multi level entity revision howto

六月ゝ 毕业季﹏ 提交于 2019-12-12 08:53:14
问题 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

How to save UTC (instead of local) timestamps for Hibernate Envers revision info?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 00:12:05
问题 Using Hibernate/Envers, how to: Save UTC (instead of local) timestamps for Hibernate Envers revision info? Get timestamps as a LocalDateTime (Java 8)? 回答1: 1) From the revision listener, call the fixTimezone method of the revision, as shown below. 2) To get it as LocalDateTime use the getRevisionDate method, as shown below. public class MyRevisionListener implements RevisionListener { @Override public void newRevision(Object revisionEntity) { MyRevision revision = (MyRevision)revisionEntity;

Setting the revision date manually with Hibernate Envers

江枫思渺然 提交于 2019-12-11 18:02:33
问题 As far as I know, Hibernate Envers stores a revision when you create, change or delete an object annotated with @Audited. Envers sets automatically the revision date to the current time. Is it possibile to set this time manually? I'd need this to handle a temporal collection where data has valid time, which I'd need to set manually. 回答1: You can, but it may not seem intuitive at first. When Envers creates its revision-entity instance, several things happen. The @RevisionTimestamp annotated

Hibernate Envers custom field for user input

我的未来我决定 提交于 2019-12-11 17:12:33
问题 I'm using Spring Boot and Hibernate Envers with a custom RevisionEntity and RevisionListener to store additional information like username, ip in the revision info. It works fine. As a new requirement I also need to store modification comment from the user. So if a user changes an entity he/she also needs to enter a reason for this change. This text should be saved among the other revision information. I have the text in my Controller and in the Service class as well, but how can I populate

Envers + MYSQL + List<String> = SQLSyntaxErrorException: Specified key was too long;

孤街浪徒 提交于 2019-12-11 16:00:49
问题 I am extending an existing application with Audit support using Envers. I annotated all @Entity classes and I got a bunch of Exception traces. When taking a look at them, it seems that they all relate to attribute definitions that have the following form protected List<String> testActivities; @ElementCollection protected List<String> getTestActivities() { return testActivities; } public void setTestActivities(List<String> testActivities) { this.testActivities = FXCollections.observableList

Get audit table name from hibernate envers?

风格不统一 提交于 2019-12-11 15:46:00
问题 Is it possible to request the name of an audit table for a entity from Hibernate envers? I don't mean the solution of getting Hibernate table name for entity and appending the auditing postfix. 回答1: In Hibernate Envers 5.x, there is no centralized way to obtain this information so you'll have to consult several APIs to get this metadata. But there is HHH-12014 and HHH-12044 that highlight the need to expose this so that it can be consumed by user code easier. In order to gain access to this

Hibernate Envers: Auditing an object, calling merge on it, gives an audit record EVERY time even with no change?

守給你的承諾、 提交于 2019-12-11 07:42:05
问题 As in the title. I would expect Envers to only insert an audit record if the data has actually changed (have tried to help Envers along by providing equals and hashCode methods) - does this not come as standard? Many thanks 来源: https://stackoverflow.com/questions/26892191/hibernate-envers-auditing-an-object-calling-merge-on-it-gives-an-audit-record

Envers, for a ManyToOne with JoinColumn, is auditing the wrong column

安稳与你 提交于 2019-12-11 06:34:14
问题 When auditing a foreign key, Envers seems to be ignoring the JoinColumn annotation. E.g. I have a simple class like this: @Audited @Entity public class Address { @Id @GeneratedValue private int id; @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) @ManyToOne @JoinColumn (name="addressTypeFk", referencedColumnName="EntityId",nullable=false) private AddressTypeLookup addressType; Which references a lookup table like this: @Entity public class AddressTypeLookup { @Id

Can hibernate envers return the latest revision of all entities of a specific type?

给你一囗甜甜゛ 提交于 2019-12-11 05:53:35
问题 I am having a huge problem trying to get Envers to execute the query I need. If anyone can let me know if this is possible from within Envers or if I need to excute the SQL directly that would be a tremendous help! Here is the problem. I have a made-up "Project" entity - any Entity class will do - that is audited. I am trying to get the latest revision of EVERY Project entity via an AuditReader query. When I do this (the other parts of the code shouldn't matter): AggregatedAuditExpression