How to disable envers auditing for spring boot - java

i am creating a maven multimoduled project one of the module for the hibernate entity only , issue is two services/api/maven_project are using same module , but one requires auditing but other dont , how i can keep my code intact (means ,without changing or removing #Audited annotation) , how to enable or disable envers auditing at run time or compile time,
because after everything i have tried auditing is working for both api
i have tried
spring.jpa.properties.hibernate.integration.envers.enabled=false
spring.jpa.properties.hibernate.listeners.envers.autoRegister=false
spring.jpa.properties.hibernate.envers.autoRegisterListeners=false
hibernate.integration.envers.enabled=false
hibernate.listeners.envers.autoRegister=false
hibernate.envers.autoRegisterListeners=false

As per buræquete's answer
spring.jpa.properties.hibernate.integration.envers.enabled=false
Would do the job.
"Non-Spring Data JPA" Hibernate properties are configured through
spring.jpa.properties.hibernate.*

Related

How to prevent Hibernate Envers for creating Audit tables?

In my case, i have a dependency to a module that implementing envers in its domains (its domains were annotated with #Audited). When i imported that module in my pom.xml and run my app, envers automatically creating audit tables based on its domains. My question, how can i prevent Envers for creating audited tables after the domains were annotated with #Audited? Is there any solution like adding a configuration in application.properties file or something like that?
org.hibernate.envers.table_creation = false
If you're importing a dependency that uses Envers but you do not require the tables or its functionality in your environment, you can easily disable Envers via a simple hibernate setting
hibernate.integration.envers.enabled=false
This should prevent Envers from bootstrapping and building any envers schema and it should also prevent the event listeners from being registered when entity model events fire where we track changes and generate the audit entries.

Java Framework to maintain entity history automatically

I am working on a project where I need to create history of particular table automatically. I have used #Audited annotation for it but it's creating duplicate data in table.
I am running out of space due to duplicate data.Even EclipseLink is not sloving my problem.
You tagged your question with Hibernate, but if switching to Eclipselink would be an option for you, be sure to check out the History Policy feature of Eclipselink. It allows automatic historization of data.
Please check Hibernate Envers.
This component integrates with JPA and Hibernate, and takes care of maintaing a revision history for any #Audited annotated Entity.
There are some guides on the net:
Maintain the data versioning info with Spring Data — Envers
Spring Boot : How to add JPA and Hibernate Envers Auditing
Spring Boot + Hibernate + Hibernate Envers

How can I generate entities classes from database using Spring Boot and IntelliJ Idea?

I trying to make a project using the Spring Initializr wizard and I already have a database, so I want to generate entities classes using Spring Boot and IntelliJ Idea.
Prerequisites are:
You have your Spring Boot project initialized correctly in IDEA
JPA persistence.xml file or similar has been generated correctly
Then you have to do these things:
Create a DataSource - here you will add a simple DataSource that will connect to your database. The setup should be intuitive - you only provide connection details and add DB drivers (IDEA can download them for you)
Add JPA/Hibernate facet. You can do it like this or this.
Now you should be able to generate entities using IDEA. What you want to do here is choose Generate by Database Schema. The dialog will let you select the tables you want to use, the rest should be up to you.

Is it possible to use Envers 4 with Hibernate 3?

Currently, we are using the version 3.6.9.Final for all our Hibernate libraries, including Hibernate Envers for our audit revisions.
We want to move to the 4.1.8.Final version (to use the #Audited(withModifiedFlag = true) among others things), but only for Hibernate Envers. Unfortunately, it does not seem to work. When I modify an #Audited entity, Envers does not save the revision.
Maybe it's due to the definition of the listeners? With 3.6.9, I set the following properties in my hibernate.properties file:
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
As far as I know, the version 4 of Envers does not need these declarations anymore. Without them, I get no error, but the revision are not created. I can't set these declarations back, as the classes are not the same between v3 and v4 (especially org.hibernate.envers.event.AuditEventListener that does not exist anymore).
So is there a way to make it work?
No, that is not possible, you must use the same Hibernate and Envers versions.

Migrate to Hibernate Annotations from plain hibernate configuration - Also Database needs FK

Currently I have following scenario with my project :
Implemented Hibernate Configuration files (xml) mapping
Database doesn't have any FK relationship yet
So Now I wanna know that what are the things I need to keep in mind before migrating from hibernate xml configuration to hibernate annotations.
One more thing I wanna specify here is right now with my db i don't have any kind of FK relationship defined....
So obviously I will be applying FK first and then start migrating to annotations...
With this scenario Can anybody have any specific suggestion that I should follow ?
Thanks in advance...
Be very careful. Where I work we do everything with annotations so there shouldn't be any specific limitations as far as I can foretell.
It might be wise to migrate a logic chunk of your code at a time if at all possible. But basically it's just painstakingly running through your code and copying everything from the cofnig xml to your entity classes.

Categories

Resources