1

I do replace of Hibernate 4 to Hibernate 5 and now facing an issue with connection's metadata. Code snippet is:

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;
}

This piece of code compiles, but gives me a java.lang.ClassCastException: com.mchange.v2.c3p0.impl.NewProxyDatabaseMetaData cannot be cast to org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo.

Is there a correct way to do this? Hibernate 4 worked for me without that cast.

Thank you.

4

1 に答える 1