我确实将 Hibernate 4 替换为 Hibernate 5,现在面临连接元数据的问题。代码片段是:
public long getNext(final String sequenceName) {
ReturningWork<Long> maxReturningWork = new ReturningWork<Long>() {
@Override
public Long execute(Connection connection) throws SQLException {
DialectResolver dialectResolver = new StandardDialectResolver();
>>>>> problem is here >>>>>> Dialect dialect = dialectResolver.resolveDialect((DialectResolutionInfo)connection.getMetaData());
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
preparedStatement = connection.prepareStatement( dialect.getSequenceNextValString(sequenceName));
resultSet = preparedStatement.executeQuery();
resultSet.next();
return resultSet.getLong(1);
}catch (SQLException e) {
throw e;
} finally {
if(preparedStatement != null) {
preparedStatement.close();
}
if(resultSet != null) {
resultSet.close();
}
}
}
};
Long maxRecord = databaseUtilities.getSession().doReturningWork(maxReturningWork);
return maxRecord;
}
这段代码可以编译,但给了我一个 java.lang.ClassCastException:com.mchange.v2.c3p0.impl.NewProxyDatabaseMetaData cannot be cast to org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo。
有没有正确的方法来做到这一点?Hibernate 4 在没有那个演员表的情况下为我工作。
谢谢你。