问题描述
我有一个名为 customer 的 JPA 实体
,就像这样
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 插件
!它能够为 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 没有给我预期的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!