我有以下问题:
这是我为给定的
public class SearchRepoImpl<T, ID extends Serializable> implements SearchRepo<T,ID> {
private final EntityManager em;
@Override
public Stream<T> findStreamBySpec(Specification<T> where, Integer limit, Class<T> clazz) {
final Class<T> domainClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<T> query = builder.createQuery(domainClass);
applySpecificationToCriteria(where, domainClass, query); // this method does the necessary preprocessing and is of no interest
return em.createQuery(query)
.getResultStream()
.limit(limit.longValue());
}
}
但是,当我使用searchRepo.findStreamBySpec(spec, 100, MyClass.class).forEach(e-> {...})
调用此实现时,我会遇到以下异常:
org.hibernate.exception.GenericJDBCException:由于调用isBeforeFirst或isAfterLast()时发生异常,无法确定结果集是否为空
我已经设法将这个问题追溯到DB2驱动程序中的一行反编译代码:
private final void checkThatResultSetTypeIsScrollable() throws SQLException {
if (this.resultSetType_ == ResultSet.FORWARD_ONLY) {
throw hd.a(this, this.agent_.logWriter_, ErrorKey.METHOD_NOT_ALLOWED_ON_FORWARD_ONLY_CURSOR, "10900");
}
}
此方法又从HikariProxyResultSet调用
public boolean isBeforeFirst() throws SQLException {
this.agent_.systemMonitor_.c();
boolean var2;
try {
if (this.agent_.loggingEnabled()) {
this.agent_.logWriter_.traceEntry(this, "isBeforeFirst");
}
this.checkForClosedResultSet();
this.checkThatResultSetTypeIsScrollable();
//^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ calls above method checkThatResultSetTypeIsScrollable()
boolean var1 = this.isBeforeFirstX();
if (this.agent_.loggingEnabled()) {
this.agent_.logWriter_.traceExit(this, "isBeforeFirst", var1);
}
var2 = var1;
} finally {
this.agent_.systemMonitor_.a(this.statement_);
}
return var2;
}
它是从
private boolean isResultSetEmpty() {
try {
return currentPosition == 0 && !getResultSet().isBeforeFirst() &&
!getResultSet().isAfterLast();
//^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ calls above method isBeforeFirst()
}
catch (SQLException e) {
throw getSession().getFactory().getSQLExceptionHelper().convert(
e,
"Could not determine if resultset is empty due to exception calling isBeforeFirst or isAfterLast()"
);
}
}
我的问题是,是否有办法向Hibernate、HikariCP和/或DB2暗示或建议我不想将ResultSet
设置为FORWARD_ONLY
,或者我不想使用那种可滚动的结果。
1条答案
按热度按时间vyswwuz21#
您需要从服务调用存储库,并使用@Transactional对其进行 Package