1
我將Hibernate 4替換爲Hibernate 5,現在面臨着連接元數據的問題。代碼片段:Hibernate 5:如何將連接的元數據轉換爲DialectresolutionInfo
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不能轉換爲org.hibernate.engine.jdbc。 dialect.spi.DialectResolutionInfo。
有沒有正確的方法來做到這一點? Hibernate 4爲我工作沒有演員。
謝謝。
問題解決autowirin g SessionFactory並從中取出Dialect。 – maksim2020