spring4 + jaxb + jpa + hibernate-envers在websphere + oracle11g上有应用
有2种Java方法,它们可以获取用户实体的历史记录: 从rest-控制器调用的方法getHistoryUser,它查找一个id的所有版本,并从所有使用此id和版本的用户中读取。 extractUsers-只需将JPA-实体映射到String
我在websphere jdbc-resource上具有用于base和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实体中,有任何字段和@Audit批注用于使用hibernate-envers
在日志中,我也看到了一种关注警告。
[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?
答案 0 :(得分:0)
您是否尝试过关闭entityManager?
类似这样的东西:
EntityManager entityManager = entityManagerFactory.createEntityManager();
AuditReader auditReader = AuditReaderFactory.get(entityManager);
...
entityManager.close();
我也有同样的问题。