liquibase:diff没有给我预期的结果 [英] liquibase:diff not giving me expected result
问题描述
我有一个叫JPA entity
的客户,就这样
I have a JPA entity
called customer and goes like this
@Entity
public class Customer {
private int custNo;
private String custName;
private String country;
public Customer() {
}
public Customer(int custNumber, String custName, String country) {
this.custNo = custNumber;
this.custName = custName;
this.country = country;
}
public int getCustNo() {
return custNo;
}
public void setCustNo(int custNo) {
this.custNo = custNo;
}
public String getCustName() {
return custName;
}
public void setCustName(String custName) {
this.custName = custName;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
我的数据库有2个表:-BE132_name和BE1jj231_address,
and my db has 2 tables :- BE132_name and BE1jj231_address ,
我正在运行个人资料liquibase:diff
,并给了我如下的更改集
I am running my profile liquibase:diff
and is giving me the change set as follows
<changeSet author="jobs (generated)" id="1554122585461-10">
<dropTable tableName="BE132_name"/>
</changeSet>
<changeSet author="jobs (generated)" id="1554122585461-11">
<dropTable tableName="BE1jj231_address"/>
</changeSet>
由于您没有看到对应的JPA
实体,因此可以看到它创建了放置表.但是为什么不为我的客户创建create script
?
As you can see it created drop table since I dont have its corresponding JPA
entities. But why is it not creating the create script
for my Customer ?
对于一个空的数据库(一个没有任何表的数据库),我得到
For an empty data base (one without any tables) , I am getting
INFO 4/2/19 5:47 PM: liquibase: No changes found, nothing to do
推荐答案
我为此使用了liquibase-hibernate plugin
!即使它的对应表不在数据库中,它也能够为JPA实体生成changeset
.
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.
插件
<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>
和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
referenceUrl
正在使用程序包扫描,因此必须使用方言参数. changeLogFile
是与数据库同步的变更集的位置. diffChangeLogFile
是必须清除差异更改日志的位置.
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.
这篇关于liquibase:diff没有给我预期的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!