I am upgrading hibernate version from 5.1.17 to 5.4.11 and mssql-jdbc version to 7.2.2.jre8 . I am connecting to MS sql server
But while starting the server , I am getting below error message
Caused by: java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Long
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:74)
at com.mchange.v2.c3p0.impl.NewPooledConnection.handleThrowable(NewPooledConnection.java:505)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getLong(NewProxyResultSet.java:491)
at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.resultSetStartValueSize(SequenceInformationExtractorLegacyImpl.java:129)
at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.extractMetadata(SequenceInformationExtractorLegacyImpl.java:59)
at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.initializeSequences(DatabaseInformationImpl.java:65)
at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.(DatabaseInformationImpl.java:59)
at org.hibernate.tool.schema.internal.Helper.buildDatabaseInformation(Helper.java:155)
… 127 more
Caused by: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Long
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getLong(SQLServerResultSet.java:2328)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getLong(NewProxyResultSet.java:477)
… 132 more
In my opinion that is a bug in Hibernate (see also https://hibernate.atlassian.net/browse/HHH-13805 and https://discourse.hibernate.org/t/sql-server-could-not-fetch-the-sequenceinformation-from-the-database/4083). In SQL Server sequences are typed that is they can be int, smallint, long, … That is reflected in the meta data returned by the INFORMATION_SCHEMA.SEQUENCES view. However, Hibernate assumes that the schema columns holding the min, max and current values for the sequence are always of type long. That is not the case. They are holding and returning values of the type of the defined sequence. I recently had to work around that problem and wrote my own custom dialect with a custom implementation of the SequenceInformationExtractorLegacyImpl class that deals with the multiple types.