I have an app with customised Revision entity, but when I deploy, it creates a REVINFO default one:
The Revision Entity:
@Entity
@Table(name = "CustomRevisionEntity", catalog = "molecular")
@RevisionEntity(CustomRevisionEntityListener.class)
public class CustomRevisionEntity extends DefaultRevisionEntity {
private String username;
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
}
Revision Entity Listener:
public class CustomRevisionEntityListener implements RevisionListener {
public final static String ANONYMOUS_USERNAME = "anonymous";
@Override
public void newRevision(Object revisionEntity) {
CustomRevisionEntity exampleRevEntity = (CustomRevisionEntity) revisionEntity;
String currentUserLogin;
if(SecurityUtils.getCurrentUserLogin().isPresent())
currentUserLogin = SecurityUtils.getCurrentUserLogin().get();
else
currentUserLogin = ANONYMOUS_USERNAME;
exampleRevEntity.setUsername(currentUserLogin);
}
Spring profile properties:
jpa:
database-platform: org.hibernate.dialect.MySQL5Dialect
database: MYSQL
show-sql: true
generate-ddl: true
hibernate:
ddl-auto: update
naming:
physical-strategy: org.wwarn.surveyorDM.config.HibernateAuditTablesNamingStrategy
properties:
hibernate.id.new_generator_mappings: false
hibernate.cache.use_second_level_cache: true
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
hibernate.cache.region.factory_class: org.hibernate.cache.jcache.JCacheRegionFactory
Envers version is 5.2.12
This question is not applicable because I use Spring boot and don't have .xml file with manual mappings
I really can't see that I'm doing anything different from the official guide Any ideas here?
Ok, so I will leave the answer as to how I sorted this out, just for in case it can help anyone else in the same situation.
In Spring we have the option to specify the entities we want the app to scan for when it starts up, in my case I needed to specify this provided I had to import entities from other modules via maven, so when adding an entityScan such as:
@EntityScan(basePackages = {
"org.wwarn.malaria.server.data",
"org.wwarn.chassis.server.data",
"org.wwarn.surveyorDM.domain.vivax",
"org.wwarn.surveyorDM.domain"})
We're telling our app to search for Entities in those packages and those packages only, my config for RevisionEntity was in config.envers, so all I had to do was add the following line to my @EntityScan and I could personalize the Revision Entity:
"org.wwarn.surveyorDM.config.envers"