“Cannot find database driver: Driver class was not specified and could not be determined from the url” error on using liquibase-hibernate plugin

三世轮回 提交于 2021-01-04 05:57:46

问题


I am trying to generate changeLog from diffs between a Database and Persistence Entities.

I am using the liquibase hibernate plugin

<plugins>
    <plugin>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-maven-plugin</artifactId>
        <version>3.4.1</version>
        <configuration>                  
            <propertyFile>src/main/resources/liquibase.properties</propertyFile>
        </configuration> 
        <dependencies>
            <dependency>
                <groupId>org.liquibase.ext</groupId>
                <artifactId>liquibase-hibernate4</artifactId>
                <version>3.5</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>4.1.7.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-jpa</artifactId>
                <version>1.7.3.RELEASE</version>
            </dependency>
        </dependencies>               
    </plugin> 
</plugins> 

and my liquibase.properties goes like this

changeLogFile=classpath:liquibase-changeLog.xml
url=jdbc:postgres://localhost:5432/oauth_reddit
username=tutorialuser
password=tutorialmy5ql
driver=org.postgresql.Driver
referenceUrl=com.sample.App
  ?dialect=org.hibernate.dialect.PostgreSQLDialect
diffChangeLogFile=src/main/resources/liquibase-diff-changeLog.xml

while executing mvn liquibase:diff, I am getting the following error

[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.4.1:diff (default-cli) on project prototype-liquibase-migration: Error setting up or running Liquibase: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (com.sample.App?dialect=org.hibernate.dialect.PostgreSQLDialect) -> [Help 1]

I have specified the Driver in the liquibase properties, but it seems that it is not taking.What could have I done wrong ?


回答1:


The problem was with my referenceUrl in liquibase.properties The referenceUrl is using package scan, so the url has to start with hibernate:spring:.

I changed

referenceUrl=com.sample.App?=org.hibernate.dialect.PostgreSQLDialect

into

referenceUrl=hibernate:spring:com.sample.App?dialect=org.hibernate.dialect.PostgreSQLDialect

This solved my problem.



来源:https://stackoverflow.com/questions/57158781/cannot-find-database-driver-driver-class-was-not-specified-and-could-not-be-de

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!