spring4+jaxb+jpa+hibernate-envers上有应用可以在websphere + oracle11g上运行
有 2 个 java 方法,可以获取用户实体的历史记录: 从其余 Controller 调用 getHistoryUser 方法,该方法查找一个 id 的所有版本,并从基础读取使用此 id 和版本的所有用户。 extractUsers - 只需将 JPA - 实体映射到 String
我在 websphere jdbc-resource 上有基本参数和 poolConnection - 参数。默认情况下最大可用池连接数为 10。 我对这个值有一个错误 - 服务没有响应并且所有连接都被中断。 我可以使用 40 个池连接的解决方法,并且它可以工作。
当客户端调用 getHistoryUser 方法时 - 我没有可用的连接,您能帮忙说出原因吗?
public String getHistoryUser(String id) {
logger.log(Level.INFO, "get history id=" + id);
AuditReader auditReader = AuditReaderFactory.get(entityManagerFactory.createEntityManager());
List<Number> auditVersions = auditReader.getRevisions(UserRecord.class, id);
List<UserRecord> userRecords = auditVersions.stream().map(item -> {
UserRecord elem = auditReader.find(UserRecord.class, id, item.intValue());
elem.setVersion(item.intValue());
return elem;
}).collect(Collectors.toList());
StringBuilder result = new StringBuilder();
extractUsers(UserRecords).stream().forEach(item -> {
result.append(item);
});
return result.toString();
}
private List<String> extractUsers(List<UserRecord> userRecords) {
logger.log(Level.INFO, "extractUserRecords..");
if (CollectionUtils.isEmpty(userRecords) || userRecords.stream().allMatch(x -> x == null)) {
return new ArrayList<>();
}
return riskMetricRecords.stream().map(userRecord -> {
String userRecord = (String) deserialize(userRecord.getUser());
return appendMetaInfoInEntity(user, "<User>", userRecord.getPrKey(), Integer.toString(userRecord.getVersion()));
}).collect(Collectors.toList());
}
在我的 JPA 实体中,有用于使用 hibernate-envers 的任何字段和 @Audit 注释
在日志中我也看到了一个有趣的警告..
[2/27/19 10:50:32:516 MSK] 00000103 SystemOut O [2019-02-27 10:50:32.516] WARN ework.orm.jpa.vendor.HibernateJpaDialect JDBC Connection to reset not identical to originally prepared Connection - please make sure to use connection release mode ON_CLOSE (the default) and to run against Hibernate 4.2+ (or switch HibernateJpaDialect's prepareConnection flag to false
How to fix this issue. It just code bug or some fueture of hibernate?
最佳答案
您是否尝试过关闭entityManager?
类似这样的事情:
EntityManager entityManager = entityManagerFactory.createEntityManager();
AuditReader auditReader = AuditReaderFactory.get(entityManager);
...
entityManager.close();
我也遇到了同样的问题。
关于java - 使用 hibernate - envers 并获取历史记录时,池连接没有空闲连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54930415/