hibernate-envers

Work around for envers auditing for bulk update

╄→尐↘猪︶ㄣ 提交于 2019-12-01 23:44:20
In the application which I am working on I use spring, hibernate and envers for auditing. envers works with calls like, hibernateTemplate.insert , hibernateTemplate.save , hibernateTemplate.saveOrUpdate . But it doesnt seem to work when i call hibernateTemplate.bulkUpdate . I googled for solutions and found that envers doesnt support bulkUpdate. A work around has been provided in the link below but i am not able to get it. Envers Bulk insert/updates It would be of help if someone can provide a workaround/sample for this. Thanks The documentation is correct. HQL and native SQL operations are

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

和自甴很熟 提交于 2019-12-01 19:58:33
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 order to get the Hibernate Envers to actually write the audit records to the corrsponsing x_aud and

hibernate envers: merge & saveOrUpdate

吃可爱长大的小学妹 提交于 2019-11-30 15:55:59
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 the right way? And also i am curious that why saveOrUpdate is not throwing any error now. Hibernate

Getting the old value and new value between two revisions with Hibernate Envers

ぐ巨炮叔叔 提交于 2019-11-29 16:44:49
This is a follow up question to Retrieve audited entities name, old value and new value of the given revision I have figured out how to get the two revision of an entity but don't see any easy to find the difference between the two. Is there anything in envers that will help doing a diff of an entity at different revisions? Or any good libraries? I would be really cool if I could get the property modified (_mod) field fields. So what I came up with to make life easier was to create an annotation to mark the fields I was interested in comparing. Without I ended up having to get with sticking to

Conditional Envers Auditing

岁酱吖の 提交于 2019-11-29 13:58:24
问题 I have a requirement where I want to audit records only on change of Status field. I've followed documentation chapter tutorial "15.8. Conditional auditing". Step 1: Turn off automatic Envers event listeners registration. I have following: <prop key="hibernate.listeners.envers.autoRegister">false</prop> Step 2: Create subclasses for appropriate event listeners. public class DeleteEnversListener extends EnversPostDeleteEventListenerImpl { private static final long serialVersionUID =

How to retrieve the audited revision of relations?

我是研究僧i 提交于 2019-11-29 12:05:02
Here is my use case I have two entities : Personn and Email (a @OneToMany relation). Both of them are audited. First I create a new Personn, with an Email (=> Both of them have a revision 1), then I modify the Email (=> The Email has a revision 2, but Personn has only a revision 1) In the web application the end-user has only one view to show the Personn's attributs and also his Emails attributs. In this view I want to show all existing revisions for this Personn. But when I query the audit system, it doesn't show me revision 2 as the Personn has not been modified. I understand the technical

Hibernate Envers fails with @Converter and AttributeConverter (JPA 2.1)

穿精又带淫゛_ 提交于 2019-11-29 04:38:29
I am using Hibernate 4.3.4 with Envers, and MySql 5.6. Without a JPA 2.1 converter, the Party entity below fails at Configuration.buildSessionFactory() as it should, since Hibernate doesn't know what to do with the Name class: @Entity @Audited public class Party { protected Name name; ... } The exception is: org.hibernate.MappingException: Could not determine type for: ModuloADM.Party.Name, at table: Party, for columns: [org.hibernate.mapping.Column(name)] To fix this, I then add this converter: @Converter (autoApply=true) public class NametoStringConverter implements AttributeConverter<Name,

Find max revision of each entity less than or equal to given revision with envers

独自空忆成欢 提交于 2019-11-28 12:54:00
This might be simple, but unable to find a way. I am trying to find max revision of each entity less than or equal to given revision number. AuditQuery query = getAuditReader().createQuery().forRevisionsOfEntity( entityClass, false, false); query.add(AuditEntity.revisionNumber().le(revisionNumber)); query.addOrder(AuditEntity.revisionNumber().desc()); query.getResultList(); Above code returns multiple revisions of same entity in descending order. I would like to get latest distinct revision of each entity less than or equal to given revision number. As a workaround, I am filtering resultSet as

Extending Hibernate Envers Implementation

笑着哭i 提交于 2019-11-28 12:44:51
I have 2 maven projects that share a JPA project as a dependency in their individual POMs. The JPA project is on ver 2.1 and has hibernate envers implemented successfully. However I now need to create a custom RevisionEntity as I need to audit extra properties such as the logged in user id. Problems are: i. I cant implement this directly in the JPA project ii. The implementation for retrieving the logged in user differs for the parent maven projects. The real challenge is actually in implementing the RevisionListener. I tried creating an abstract class revisionlistener within the JPA project

Getting the old value and new value between two revisions with Hibernate Envers

拥有回忆 提交于 2019-11-28 11:38:05
问题 This is a follow up question to Retrieve audited entities name, old value and new value of the given revision I have figured out how to get the two revision of an entity but don't see any easy to find the difference between the two. Is there anything in envers that will help doing a diff of an entity at different revisions? Or any good libraries? I would be really cool if I could get the property modified (_mod) field fields. 回答1: So what I came up with to make life easier was to create an