Im using Hibernate Envers and created a custom REVINFO entity. The entity was:
@Entity
@RevisionEntity(AuditRevisionListener.class)
@Table(name = "envers_info", catalog = "another_catalog")
public class AuditEnversInfo extends DefaultRevisionEntity {
@Column(name = "user_id")
private String userId;
}
My question is, how can I replace the value of catalog field on @Table annotation based on external config file such as application.properties value in SpringBoot? I want it be dynamic so once I change the external config file to another catalog/schema, it will be automatically change its catalog/schema to persist the audited record.
Envers allows you to set this value via configuration by specifying one of two values, depending on your database platform's implementation.
org.hibernate.envers.default_schema
org.hibernate.envers.default_catalog
Since you have determined your database platform wants to use the catalog configuration rather than the schema configuration, then you simply need to provide this in your normal hibernate property configuration file as
org.hibernate.envers.default_catalog=another_catalog
You can define this configuration in a number of places
application.yml
or application.properties
file used by spring-boot
.Session
or EntityManager
factory.hibernate.properties
file in the root of your application's class path.