liquibase:diff not giving me expected result

后端 未结 1 1218
醉酒成梦
醉酒成梦 2021-01-17 04:28

I have a JPA entity called customer and goes like this

@Entity
public class Customer {



private int custNo;
private String custName;
private          


        
相关标签:
1条回答
  • 2021-01-17 05:25

    I used the liquibase-hibernate plugin for this!. It is capable of generating the changeset for a JPA entity even if its corresponding table is not there in the db.

    The 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 the liquibase.properties

    changeLogFile=classpath:liquibase-changeLog.xml
    url=jdbc:mysql://localhost:3306/oauth_reddit
    username=tutorialuser
    password=tutorialmy5ql
    driver=com.mysql.jdbc.Driver
    referenceUrl=hibernate:spring:org.baeldung.persistence.model
      ?dialect=org.hibernate.dialect.MySQLDialect
    diffChangeLogFile=src/main/resources/liquibase-diff-changeLog.xml
    

    The referenceUrl is using package scan, so the dialect parameter is required. changeLogFile is the location of changeset for which the db is in sync. diffChangeLogFile is the location where the difference changelog has to be flushed.

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