hibernate-envers

Why Hibernate Envers is ignoring my custom RevisionEntity?

不羁岁月 提交于 2019-12-21 20:19:07
问题 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.

Hibernate/Envers unable to read the mapped by attribute

左心房为你撑大大i 提交于 2019-12-21 09:29:34
问题 I am unable to implement many-to-many relation using join table (https://stackoverflow.com/a/7603036 & https://en.wikibooks.org/wiki/Java_Persistence/ManyToMany#Mapping_a_Join_Table_with_Additional_Columns). When I try to reproduce it persistence unit is unable to build EntityManagerFactory. It seems that Envers fails to read the mapped by attribute, although it looks good to me. What am I doing wrong? What is the right way™ to implement many-to-many relation with extra columns (and Envers)?

How to generate Envers database schema with org.hibernate.tool.EnversSchemaGenerator?

心不动则不痛 提交于 2019-12-21 05:26:11
问题 I updated Hibernate to the 4.1.1.Final version. According to the documentation There are 2 ways to generate a database schema: Ant task org.hibernate.tool.ant.EnversHibernateToolTask . Run org.hibernate.tool.EnversSchemaGenerator from Java. Hibernate-tools doesn't work with Hibernate-4.1.1.Final. It has a blocking bug. I found only release notes and a test case. So how can I use org.hibernate.tool.EnversSchemaGenerator with my persistence.xml and Maven? Update: Found related thread on the

Hibernate Envers: Retrieving the right revisions of an entity with a collection property

跟風遠走 提交于 2019-12-20 07:24:01
问题 I have two audited entities, A and B. Entity A holds a collection of entity B (annotated as One-to-many relationship). When inserting a new instance of A into the database, all rows of A and B are at the same revision (let's say revision 1). Then, there is an update on A which only affect the instances of entity B. So after the update, the entity A is still at revision 1, whereas the entities of B are at revision 2 (including a MOD entry in the audit table). In Revision 3, the entity A is

Hibernate envers - How to store only updated values

本小妞迷上赌 提交于 2019-12-20 03:42:21
问题 I am using Hibernate Envers for my Auditing. Post-update and post-insert works fine. I have a requirement where I need to audit only the updated columns in the audit table (e.g. employee_aud). By default envers will insert the entire persisted entity in to the audit table. I need to insert values only which are updated. Is there any possibility to do this ? Thanks in advance. Cheers ! 回答1: What happens if you dont configure envers listener for post-insert? I mean if you take out post-insert

Hibernate Envers - Doesn't write audit records for createQuery(…).executeUpdate(), only .persist() and .merge()

主宰稳场 提交于 2019-12-20 01:36:48
问题 I have 3 ways things get written to the DB public void create(T object) { entityManager.persist(object); } public void update(T object) { object = entityManager.merge(object); } public int updateStatus(String id, String status) { final int changes = entityManager.createQuery("update item set state = :newState," + " last_modified = current_timestamp" + " where id = : id ") .setParameter("newState", status) .setParameter("id", id) .executeUpdate(); return changes; } The problem I have, is in

Spring Data JPA and Spring Boot auditing with Hibernate Envers

蹲街弑〆低调 提交于 2019-12-19 10:27:18
问题 I am using Spring Data JPA and Spring Boot for my project. I have Audit requirement for Objects(Create/Update/Delete). I may need to get Audit revisions for particular objects too. I have checked on net that Spring Data Envers cant get revisions and doesn't track deletions? So my Question is : 1) Can we integrate Hibernate Envers with Spring data JPA? 2) We have native queries, HQLs and Spring data JPA update/save/delete dynamic queries, so would Hibernate envers be able to track object for

hibernate envers: merge & saveOrUpdate

柔情痞子 提交于 2019-12-18 17:57:24
问题 I am working on an spring-hibernate-envers application. After lot of googling things are finally working for me but i have still got couple of questions. Earlier i was using saveOrUpdate for saving or updating entities. But when working with envers it was throwing a nonUniqueObject exception. So i used merge instead and it worked. Is it right to use merge for this? Does merge inserts new objects to db? I tried following code: entity=merge(entity); saveOrUpdate(entity); This also worked. Is it

How to put envers annotations into XML Mapping Metadata(orm.xml) file

岁酱吖の 提交于 2019-12-17 20:34:03
问题 In my application, I am using XML Mapping Metadata as an alternative to annotation. It worked fine for all the JPA annotations so far. However for Auditing, I am using Hibernate Envers. I am declaring @Audited @AuditTable("LOAN_APPLICANT_AUDIT") The only problem is how to put these annotations in XML mapping metadata form. There is a requirement that the user should specify the list of tables, which needs to be audited. Plus he should be also able to configure the name of AUDIT tables

How to access FacesContext in Hibernate Envers without Seam?

泄露秘密 提交于 2019-12-12 19:11:32
问题 We're implementing Envers in our project for database auditing, and have run into a snag. We don't know how to determine what user is making the change. All the examples I can find use Seam and their Component.getInstance technique. Glassfish 3.1.2.2 Mojarra 2.1.13 Hibernate 4.1.6.Final Here's our custom Revision Entity @Entity @RevisionEntity(CustomRevisionListener.class) public class CustomRevisionEntity { @Id @GeneratedValue @RevisionNumber private int id; private String login; getters