我有一个叫JPA entity
的客户,就这样
@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,
我正在运行我的个人资料liquibase:diff
,并按如下所示进行了更改设置
<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
?
对于一个空的数据库(一个没有任何表的数据库),我得到
INFO 4/2/19 5:47 PM: liquibase: No changes found, nothing to do
答案 0 :(得分:0)
我为此使用了liquibase-hibernate plugin
!即使它的对应表不在数据库中,它也能够为JPA实体生成changeset
。
插件
<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
是必须清除差异更改日志的位置。