Wrong hibernate dialect for MSSQL 2014

后端 未结 4 1645
悲哀的现实
悲哀的现实 2021-01-05 15:23

I have a problem with inserting entities, that use sequences, to a MSSQL 2014 database. I use hibernate that is shipped with Wildfly 10 CR4 (but in CR1 and CR2 I got the sam

相关标签:
4条回答
  • 2021-01-05 15:25

    Actually this problem comes due to non proper mapping of tables. Check tables and Entity class mappings.

    0 讨论(0)
  • 2021-01-05 15:33

    For Springboot 1.4.7 and lower add below to properties file

    spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.SQLServer2012Dialect
    
    0 讨论(0)
  • 2021-01-05 15:39

    Meanwhile the team does not solve this problem, you can create a custom dialect resolver:

    public class ScopeStandardDialectResolver implements DialectResolver {
    
    
    private static final long serialVersionUID = 1L;
    
        @Override
        public Dialect resolveDialect(DialectResolutionInfo info) {
            Dialect customDialectResolver = customDialectResolver(info);
            Log.getInstance().logInfo(Thread.currentThread().getStackTrace(), customDialectResolver.getClass().getName());
            return customDialectResolver;
        }
    
        private Dialect customDialectResolver(DialectResolutionInfo info) {
            final String databaseName = info.getDatabaseName();
            final int majorVersion = info.getDatabaseMajorVersion();
            if (isSqlServer2014(databaseName, majorVersion)) {
                return new SQLServer2012Dialect(); 
            } else {
                return StandardDialectResolver.INSTANCE.resolveDialect(info);
            }
        }
    
        private boolean isSqlServer2014(final String databaseName, final int majorVersion) {
            return databaseName.startsWith("Microsoft SQL Server") && majorVersion == 12;
        }
    
    }
    

    Then you configure in your persistence unit:

    <property name="hibernate.dialect_resolvers" value="com.oki.scope.hibernate.ScopeStandardDialectResolver" />
    

    Based in this example: http://blog.exxeta.com/2016/03/23/dynamically-resolve-hibernate-database-dialect/

    0 讨论(0)
  • 2021-01-05 15:41

    I think that your problem could be related to this known issue HHH-9570. (The link actually contains my pull request to my proposed workaround)

    Basically, as it happened before with SQL Server 2012, the StandardDialectResolver of Hibernate does not recognise SQL Server 2014 ([Major version 12]) and then the default dialect SQLServerDialect is returned, which is the one for SQL Server 2000

    0 讨论(0)
提交回复
热议问题