Sprint boot with Hibernate and MS SQL application.yml configuration

Viewed 1186

During development of Web app based on Spring Boot with Hibernate I used H2. DB schema was created on the fly with Hibernate. And it worked well. application.yml looked like this:

spring:
  application:
    name: WebApp
    # to define custom properties to ApplicationProperties.java
  h2:
    console:
      enabled: true
  jpa:
    show-sql: true
    properties:
      hibernate.format_sql: true
    hibernate:
      ddl-auto: update
      naming:
        physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
        implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy

Now I have to switch to the Microsoft SQL server. I've tried dozen different combinations, but can't get the right one.

spring:
  application:
    name: WebApp
    # to define custom properties to ApplicationProperties.java
  datasource:
    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
    url: jdbc:sqlserver://localhost;database=SomeDatabase
    username: sa
    password: somepassword
    platform: mssql
  jpa:
    show-sql: true
    properties:
      hibernate.dialect: org.hibernate.dialect.SQLServer2012Dialect
    hibernate:
      ddl-auto: update
      naming:
        physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
        implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy

pom.xml (relevant part) is:

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>7.2.2.jre8</version>
        </dependency>

<!--        <dependency>-->
<!--            <groupId>com.h2database</groupId>-->
<!--            <artifactId>h2</artifactId>-->
<!--        </dependency>-->

Errors are SQL related:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataLoader' defined in file....
   ...InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1341)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ....

How can I make this work?

0 Answers
Related