简体   繁体   中英

Why does H2 database use Hibernate Core in Springboot application

I have a simple springboot application which uses H2 in memory db. I have used following dependency in my POM

  1. spring-boot-starter-data-jpa
  2. com.h2database.h2

When I start application, It automatically create Entity tables using Hibernate Dialect. I have no where mentioned about Hibernate in my POM. So why does this happening. Why Spring is using Hibernate Dialect. Do we have any option to change this dialect to some other dialect. please help.

Well you using "spring-boot-starter-data-jpa" and "starter" notion means that it has everythingfor it to work. If you would look to https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa/2.1.3.RELEASE , this dependency also includes hibernate-core.

Starter poms in the SpringBoot ecosystem bring a bag of dependencies, which have been tested and are proven to work together. It also saves you the hustle of managing the right dependencies versions.

You're using spring-boot-starter-data-jpa - which is a starter pom for JPA - the opinionated choice here is the usage of Hiberante as JPA provider.

If you look at the source of the pom file, you will see this definition:

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.jboss.spec.javax.transaction</groupId>
                    <artifactId>jboss-transaction-api_1.2_spec</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

This is what brings hibernate to your project, although you have not explicitly declared it in your pom. The hibernate is downloaded as implicit dependency because of your spring-boot-starter-data-jpa starter pom.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM