一个数据库中的QueryBuilder不会从另一个数据库中读取其他JaversRepository创建的审计数据
QueryBuilder from one database does not read audit data created by other JaversRepository from another database
以下是我的问题。
先决条件:
Spring 使用数据库 1 启动应用程序 1(SB1)。
Spring 使用数据库 2 启动应用程序 2(SB2)。
两个应用程序都将 javers 审计数据写入 Database3。
SB1 审核实体 E1 的数据。
SB2 审核实体 E2 的数据。
SB1 中的 QueryBuilder 无法正确读取 E2 的审计数据。
它仅选取与 E2 相关的 NewObject 类型更改。
SB1的QueryBuilder可以完美读取E1的审计数据。
SB2的QueryBuilder可以完美读取E2的审计数据
如果 SB1 可以对 SB2 进行 REST 调用以从 SB2 中的 QueryBuilder 实例获取 'changes',则它可以完美运行。
SB1 中的 QueryBuilder 应该能够正确读取 E2 的审计数据,因为审计数据被假定为与 JaversRepository 实例无关。
以下代码用于 Spring 启动应用程序以获取审核记录。
@RequestMapping("/javers")
public String audit() {
QueryBuilder jqlQuery = QueryBuilder.anyDomainObject();
Changes changes = javers.findChanges(jqlQuery.withNewObjectChanges().build());
List<ChangesByCommit> changesByCommit = changes.groupByCommit();
return javers.getJsonConverter().toJson(changesByCommit);
}
以下实体、存储库、application.properties 和 'jql changes output' 用于 Spring 启动应用程序 1 (SB1)
`
包裹 com.test.javers.entitya;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "EntityA")
public class EntityA implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "APPLICATION_ID")
private String applicationId;
@Column(name = "APP_NAME")
private String appName;
@Column(name = "CREATE_DATE")
private Timestamp createDate;
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "IS_AUDIT_ENABLED")
private Boolean isAuditEnabled;
public EntityA() {
}
public String getApplicationId() {
return applicationId;
}
public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
public Timestamp getCreateDate() {
return createDate;
}
public void setCreateDate(Timestamp createDate) {
this.createDate = createDate;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getIsAuditEnabled() {
return isAuditEnabled;
}
public void setIsAuditEnabled(Boolean isAuditEnabled) {
this.isAuditEnabled = isAuditEnabled;
}
}
--------------------------------------------------------------------
package com.test.javers.repository;
import org.javers.spring.annotation.JaversSpringDataAuditable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.test.javers.entitya.EntityA;
@Repository
@JaversSpringDataAuditable
public interface EntityARepository extends JpaRepository<EntityA, String>{
}
--------------------------------------------------------------------------
spring.datasource.url=jdbc:postgresql://localhost/sandbox1
spring.datasource.username=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.password=postgres
server.port=8010
#Audit datasource configuration
spring.audit-datasource.url=jdbc:postgresql://localhost/sandboxaudit
spring.audit-datasource.username=postgres
spring.audit-datasource.password=postgres
spring.audit-datasource.driver-class-name=org.postgresql.Driver
-------------------------------------------------------------------------
[ { "changes": [ { "changeType": "NewObject", "globalId": { "entity":
"com.test.javers.entityb.EntityB", "cdoId": "IEj5tvWc850834675" },
"commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:16:02.946", "commitDateInstant": "2019-06-25T13:46:02.946Z", "id":
1.00 } } ], "commitMetadata": { "author": "EntityBUser", "properties": [ {
"key": "applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:16:02.946", "commitDateInstant": "2019-06-25T13:46:02.946Z", "id":
1.00 } } ]
`
以下是用于 Spring 启动应用程序 2 (SB2)
的实体和存储库
`
package com.test.javers.entityb;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "EntityB")
public class EntityB implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "APPLICATION_ID")
private String applicationId;
@Column(name = "APP_NAME")
private String appName;
@Column(name = "CREATE_DATE")
private Timestamp createDate;
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "IS_AUDIT_ENABLED")
private Boolean isAuditEnabled;
public EntityB() {
}
public String getApplicationId() {
return applicationId;
}
public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
public Timestamp getCreateDate() {
return createDate;
}
public void setCreateDate(Timestamp createDate) {
this.createDate = createDate;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getIsAuditEnabled() {
return isAuditEnabled;
}
public void setIsAuditEnabled(Boolean isAuditEnabled) {
this.isAuditEnabled = isAuditEnabled;
}
}
package com.test.javers.repository;
import org.javers.spring.annotation.JaversSpringDataAuditable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.test.javers.entityb.EntityB;
@Repository
@JaversSpringDataAuditable
public interface EntityBRepository extends JpaRepository<EntityB, String>{
}
spring.datasource.url=jdbc:postgresql://localhost/sandbox2
spring.datasource.username=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.password=postgres
server.port=8020
#Audit datasource configuration
spring.audit-datasource.url=jdbc:postgresql://localhost/sandboxaudit
spring.audit-datasource.username=postgres
spring.audit-datasource.password=postgres
spring.audit-datasource.driver-class-name=org.postgresql.Driver
------------------------------------------------------------------
[ { "changes": [ { "changeType": "ValueChange", "globalId": { "entity":
"com.test.javers.entityb.EntityB", "cdoId": "IEj5tvWc850834675" },
"commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:17:07.676", "commitDateInstant": "2019-06-25T13:47:07.676Z", "id":
2.01 }, "property": "description", "propertyChangeType":
"PROPERTY_VALUE_CHANGED", "left": "EntityB", "right": "WjMVxZBX" } ],
"commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:17:07.676", "commitDateInstant": "2019-06-25T13:47:07.676Z", "id":
2.01 } }, { "changes": [ { "changeType": "ValueChange", "globalId": {
"entity": "com.test.javers.entityb.EntityB", "cdoId": "IEj5tvWc850834675" },
"commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:16:02.946", "commitDateInstant": "2019-06-25T13:46:02.946Z", "id":
1.00 }, "property": "applicationId", "propertyChangeType":
"PROPERTY_VALUE_CHANGED", "left": null, "right": "IEj5tvWc850834675" }, {
"changeType": "ValueChange", "globalId": { "entity":
"com.test.javers.entityb.EntityB", "cdoId": "IEj5tvWc850834675" },
"commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:16:02.946", "commitDateInstant": "2019-06-25T13:46:02.946Z", "id":
1.00 }, "property": "description", "propertyChangeType":
"PROPERTY_VALUE_CHANGED", "left": null, "right": "EntityB" }, {
"changeType": "NewObject", "globalId": { "entity":
"com.test.javers.entityb.EntityB", "cdoId": "IEj5tvWc850834675" },
"commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:16:02.946", "commitDateInstant": "2019-06-25T13:46:02.946Z", "id":
1.00 }
} ], "commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:16:02.946", "commitDateInstant": "2019-06-25T13:46:02.946Z", "id":
1.00 }
} ]
`
请注意,"NewObject" 出现在两个输出中,但 'changeTypes' 的其余部分在 SB1 中不存在,即使审计数据库相同。
为此,java 应用程序可以正常工作
触发查询应该包含所有 classes
来自 jv_snapshot 在 class 路径中。在上述情况下,确保 EntityA 和 EntityB 在 class 路径中。然后你得到正确的输出。
这意味着如果 class 路径中的“更改”中没有所有 classes,您就不能 运行 在任何 jv_snapshot 中查询,否则它将 return 仅“NewObject”更改类型。
以下是我的问题。 先决条件: Spring 使用数据库 1 启动应用程序 1(SB1)。 Spring 使用数据库 2 启动应用程序 2(SB2)。
两个应用程序都将 javers 审计数据写入 Database3。
SB1 审核实体 E1 的数据。
SB2 审核实体 E2 的数据。
SB1 中的 QueryBuilder 无法正确读取 E2 的审计数据。
它仅选取与 E2 相关的 NewObject 类型更改。
SB1的QueryBuilder可以完美读取E1的审计数据。 SB2的QueryBuilder可以完美读取E2的审计数据
如果 SB1 可以对 SB2 进行 REST 调用以从 SB2 中的 QueryBuilder 实例获取 'changes',则它可以完美运行。
SB1 中的 QueryBuilder 应该能够正确读取 E2 的审计数据,因为审计数据被假定为与 JaversRepository 实例无关。
以下代码用于 Spring 启动应用程序以获取审核记录。
@RequestMapping("/javers")
public String audit() {
QueryBuilder jqlQuery = QueryBuilder.anyDomainObject();
Changes changes = javers.findChanges(jqlQuery.withNewObjectChanges().build());
List<ChangesByCommit> changesByCommit = changes.groupByCommit();
return javers.getJsonConverter().toJson(changesByCommit);
}
以下实体、存储库、application.properties 和 'jql changes output' 用于 Spring 启动应用程序 1 (SB1)
`
包裹 com.test.javers.entitya;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "EntityA")
public class EntityA implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "APPLICATION_ID")
private String applicationId;
@Column(name = "APP_NAME")
private String appName;
@Column(name = "CREATE_DATE")
private Timestamp createDate;
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "IS_AUDIT_ENABLED")
private Boolean isAuditEnabled;
public EntityA() {
}
public String getApplicationId() {
return applicationId;
}
public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
public Timestamp getCreateDate() {
return createDate;
}
public void setCreateDate(Timestamp createDate) {
this.createDate = createDate;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getIsAuditEnabled() {
return isAuditEnabled;
}
public void setIsAuditEnabled(Boolean isAuditEnabled) {
this.isAuditEnabled = isAuditEnabled;
}
}
--------------------------------------------------------------------
package com.test.javers.repository;
import org.javers.spring.annotation.JaversSpringDataAuditable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.test.javers.entitya.EntityA;
@Repository
@JaversSpringDataAuditable
public interface EntityARepository extends JpaRepository<EntityA, String>{
}
--------------------------------------------------------------------------
spring.datasource.url=jdbc:postgresql://localhost/sandbox1
spring.datasource.username=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.password=postgres
server.port=8010
#Audit datasource configuration
spring.audit-datasource.url=jdbc:postgresql://localhost/sandboxaudit
spring.audit-datasource.username=postgres
spring.audit-datasource.password=postgres
spring.audit-datasource.driver-class-name=org.postgresql.Driver
-------------------------------------------------------------------------
[ { "changes": [ { "changeType": "NewObject", "globalId": { "entity":
"com.test.javers.entityb.EntityB", "cdoId": "IEj5tvWc850834675" },
"commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:16:02.946", "commitDateInstant": "2019-06-25T13:46:02.946Z", "id":
1.00 } } ], "commitMetadata": { "author": "EntityBUser", "properties": [ {
"key": "applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:16:02.946", "commitDateInstant": "2019-06-25T13:46:02.946Z", "id":
1.00 } } ]
`
以下是用于 Spring 启动应用程序 2 (SB2)
的实体和存储库`
package com.test.javers.entityb;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "EntityB")
public class EntityB implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "APPLICATION_ID")
private String applicationId;
@Column(name = "APP_NAME")
private String appName;
@Column(name = "CREATE_DATE")
private Timestamp createDate;
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "IS_AUDIT_ENABLED")
private Boolean isAuditEnabled;
public EntityB() {
}
public String getApplicationId() {
return applicationId;
}
public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
public Timestamp getCreateDate() {
return createDate;
}
public void setCreateDate(Timestamp createDate) {
this.createDate = createDate;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getIsAuditEnabled() {
return isAuditEnabled;
}
public void setIsAuditEnabled(Boolean isAuditEnabled) {
this.isAuditEnabled = isAuditEnabled;
}
}
package com.test.javers.repository;
import org.javers.spring.annotation.JaversSpringDataAuditable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.test.javers.entityb.EntityB;
@Repository
@JaversSpringDataAuditable
public interface EntityBRepository extends JpaRepository<EntityB, String>{
}
spring.datasource.url=jdbc:postgresql://localhost/sandbox2
spring.datasource.username=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.password=postgres
server.port=8020
#Audit datasource configuration
spring.audit-datasource.url=jdbc:postgresql://localhost/sandboxaudit
spring.audit-datasource.username=postgres
spring.audit-datasource.password=postgres
spring.audit-datasource.driver-class-name=org.postgresql.Driver
------------------------------------------------------------------
[ { "changes": [ { "changeType": "ValueChange", "globalId": { "entity":
"com.test.javers.entityb.EntityB", "cdoId": "IEj5tvWc850834675" },
"commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:17:07.676", "commitDateInstant": "2019-06-25T13:47:07.676Z", "id":
2.01 }, "property": "description", "propertyChangeType":
"PROPERTY_VALUE_CHANGED", "left": "EntityB", "right": "WjMVxZBX" } ],
"commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:17:07.676", "commitDateInstant": "2019-06-25T13:47:07.676Z", "id":
2.01 } }, { "changes": [ { "changeType": "ValueChange", "globalId": {
"entity": "com.test.javers.entityb.EntityB", "cdoId": "IEj5tvWc850834675" },
"commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:16:02.946", "commitDateInstant": "2019-06-25T13:46:02.946Z", "id":
1.00 }, "property": "applicationId", "propertyChangeType":
"PROPERTY_VALUE_CHANGED", "left": null, "right": "IEj5tvWc850834675" }, {
"changeType": "ValueChange", "globalId": { "entity":
"com.test.javers.entityb.EntityB", "cdoId": "IEj5tvWc850834675" },
"commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:16:02.946", "commitDateInstant": "2019-06-25T13:46:02.946Z", "id":
1.00 }, "property": "description", "propertyChangeType":
"PROPERTY_VALUE_CHANGED", "left": null, "right": "EntityB" }, {
"changeType": "NewObject", "globalId": { "entity":
"com.test.javers.entityb.EntityB", "cdoId": "IEj5tvWc850834675" },
"commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:16:02.946", "commitDateInstant": "2019-06-25T13:46:02.946Z", "id":
1.00 }
} ], "commitMetadata": { "author": "EntityBUser", "properties": [ { "key":
"applicationID", "value": "ViralSEQ" } ], "commitDate": "2019-06-
25T19:16:02.946", "commitDateInstant": "2019-06-25T13:46:02.946Z", "id":
1.00 }
} ]
`
请注意,"NewObject" 出现在两个输出中,但 'changeTypes' 的其余部分在 SB1 中不存在,即使审计数据库相同。
为此,java 应用程序可以正常工作 触发查询应该包含所有 classes 来自 jv_snapshot 在 class 路径中。在上述情况下,确保 EntityA 和 EntityB 在 class 路径中。然后你得到正确的输出。 这意味着如果 class 路径中的“更改”中没有所有 classes,您就不能 运行 在任何 jv_snapshot 中查询,否则它将 return 仅“NewObject”更改类型。