Hibernate ENVERS auditing does not work in play 2.x.x!

94 views
Skip to first unread message

Hannah J Swystun

unread,
Jan 4, 2017, 2:32:04 PM1/4/17
to Play Framework
Hi,

I followed many docs about how integrating HIBERNATE ENVERS for auditing models but it seems that v2.x.x is not compatible with this !!!
Does someone has an idea please ? this is what i follow :

1- application.conf
hibernate.ejb.event.post-insert="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener"
hibernate
.ejb.event.post-update="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener"
hibernate
.ejb.event.post-delete="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener"
hibernate
.ejb.event.pre-collection-update="org.hibernate.envers.event.AuditEventListener"
hibernate
.ejb.event.pre-collection-remove="org.hibernate.envers.event.AuditEventListener"
hibernate
.ejb.event.post-collection-recreate="org.hibernate.envers.event.AuditEventListener"

2- Sample Model by adding annotation @Audited

package models;

import java.util.*;
import javax.persistence.*;
import javax.persistence.Column;

import com.avaje.ebean.Model;
import play.data.format.*;
import play.data.validation.*;

import com.avaje.ebean.*;
import com.avaje.ebean.Query;
import play.db.ebean.*;

import java.util.Date;  
import java.text.SimpleDateFormat;
import org.hibernate.envers.Audited;



@Entity
@Audited
public class Task extends Model implements Cloneable {
   

   
@SuppressWarnings("unused")
     
private static final long serialVersionUID = 1L;

   
@Id
   
@GeneratedValue(strategy=GenerationType.AUTO)
   
public Long id;
   
   
public String description;

   
@Formats.NonEmpty
   
public Boolean active = false;

   
@Formats.DateTime(pattern="yyyy-MM-dd HH:mm:ss")
   
public Date startdate;  
 
   
public Boolean monday = false;
   
public Boolean tuesday = false;
   
public Boolean wednesday = false;
   
public Boolean thursday = false;
   
public Boolean friday = false;                

   

   
public static Find<Long,Task> find = new Find<Long,Task>(){};    


   
}

3- No Table was created sufixed by _AUD =>  in this case a table should be created such as :

task_aud



Hannah J Swystun

unread,
Jan 4, 2017, 2:32:47 PM1/4/17
to Play Framework
Greg,

in the past you had the same problem, did you fixed it in v2 .x.x too ?
https://groups.google.com/forum/#!topic/play-framework/kfH0EPemhfE

Marcos Pereira

unread,
Jan 4, 2017, 2:42:56 PM1/4/17
to play-fr...@googlegroups.com
Hey Hanna, 

I'm not sure about how Envers works, but Hibernates reads its configuration from persistence.xml file and not from application.conf. Then, you probably need to add these configurations there.

Best,

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/f24df4f1-70b6-47b6-be4f-8db89b881e81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcos Pereira
Software Engineer, Lightbend.com

Steve Chaloner

unread,
Jan 5, 2017, 8:00:20 AM1/5/17
to Play Framework
Greg's issue was with Play 1, so that has a different configuration.

As Marcos says, I think you need to put your configuration into persistence.xml

Hannah J Swystun

unread,
Jan 5, 2017, 11:36:19 AM1/5/17
to Play Framework
Hello everybody,

unfortunatly, even with adding file persistence.xml in conf/META-INF directory , this is not working! 
<persistence
 
xmlns="http://java.sun.com/xml/ns/persistence"
 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"

 
version="1.0">
   
 
<persistence-unit name="hibernateEnvers" transaction-type="RESOURCE_LOCAL" >
     
<properties>
       
<!-- Autodetection des classes annotées @Entity -->
       
<property name="hibernate.archive.autodetection" value="class"/>
       
<!-- Configuration Envers -->
       
<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.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener" />
       
<property name="hibernate.ejb.event.pre-collection-update"
         
value="org.hibernate.envers.event.AuditEventListener" />
       
<property name="hibernate.ejb.event.pre-collection-remove"
         
value="org.hibernate.envers.event.AuditEventListener" />
       
<property name="hibernate.ejb.event.post-collection-recreate"
         
value="org.hibernate.envers.event.AuditEventListener" />            
   
</properties>
 
</persistence-unit>
       
</persistence>

+

@Audited in every entity( model)!





Le mercredi 4 janvier 2017 19:32:04 UTC, Hannah J Swystun a écrit :
Reply all
Reply to author
Forward
0 new messages