当我使用liquibase在具有@Inheritance的实体上生成变更集时,我遇到了问题(strategy = InheritanceType.TABLE_PER_CLASS)
pom.hml
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.6.2</version>
<configuration>
<!--<propertyFile>src/main/resources/liquibase.properties</propertyFile>-->
<username>synchroad_adm</username>
<password>changeme</password>
<url>jdbc:postgresql://localhost:5432/synchroad?currentSchema=synchroad_adm</url>
<referenceDefaultSchemaName>synchroad_adm</referenceDefaultSchemaName>
<defaultSchemaName>synchroad_adm</defaultSchemaName>
<referenceUrl>hibernate:spring:com.demo?dialect=org.hibernate.dialect.PostgreSQLDialect</referenceUrl>
<driver>org.postgresql.Driver</driver>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>${project.basedir}/src/main/resources/db/liquibase/app/db.changelog.xml</changeLogFile>
<diffChangeLogFile>target/changelog-diff.xml</diffChangeLogFile>
</configuration>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate5</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.23.1-GA</version>
</dependency>
</dependencies>
</plugin>
类java
@Getter
@Setter
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class MyTable {
@Id
@TableGenerator(name = "agent_generator", table = "agent_ids", pkColumnName = "seq_id", valueColumnName = "seq_value")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "agent_generator")
@Column(name = "id")
private Long id;
}
@Entity
@Table(name = "table_one")
public class TableOne extends MyTable {
}
@Entity
@Table(name = "table_two")
public class TableTwo extends MyTable {
}
我正在使用Liquibase生成我的变更集。
mvn clean install liquibase:diff
但Liquibase生成2个具有相同primaryKeyName的createTable
diff.xml
<changeSet author="mvallet (generated)" id="1535684993363-2">
<createTable tableName="table_one">
<column name="id" type="BIGINT">
<constraints primaryKey="true" primaryKeyName="MyTablePK"/>
</column>
</createTable>
</changeSet>
<changeSet author="mvallet (generated)" id="1535684993363-2">
<createTable tableName="table_two">
<column name="id" type="BIGINT">
<constraints primaryKey="true" primaryKeyName="MyTablePK"/>
</column>
</createTable>
</changeSet>
所以当我发布时
mvn clean install liquibase:update
我有一个错误错误:错误:关系“MyTablePK”已经存在。
如果我不使用liquibase但我让hibernate生成表我没有问题。
有人有想法吗?谢谢
尝试从MyTable类中删除@Entity,如果你正在使用hibernate生成的PKN是什么?为什么你需要坚持MyTable?