在引入自定义UserType之后,我编写了一个简单的Entity类及其Repository和一个单元测试类来测试UserType。
这是实体类:
@Entity
@Table(name = "person")
@TypeDef(name = "JsonDataUserType", typeClass = JsonDataUserType.class)
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
private String firstName;
private String lastName;
@Type(type = "JsonDataUserType")
private Map<String, String> additionalData;
...
}
}
我在数据库中创建了一个新的表格。
基于JHipster Creating an entity document,我创建了一个名为时间序列的databaseChangeLog XML文件
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<property name="now" value="now()" dbms="h2"/>
<property name="now" value="current_timestamp" dbms="postgresql"/>
<property name="floatType" value="float4" dbms="postgresql, h2"/>
<property name="floatType" value="float" dbms="mysql, oracle, mssql"/>
<changeSet id="20180508041900-1" author="jhipster">
<createTable tableName="person">
<column name="id" type="bigint" autoIncrement="${autoIncrement}">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="first_name" type="varchar(80)">
<constraints nullable="false" />
</column>
<column name="last_name" type="varchar(80)">
<constraints nullable="true" />
</column>
<column name="additional_data" type="jsonb">
<constraints nullable="false" />
</column>
<!-- jhipster-needle-liquibase-add-column - JHipster will add columns here, do not remove-->
</createTable>
</changeSet>
<!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here, do not remove-->
睾丸(gradlew测试)失败。错误堆栈如下:
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: javax.persistence.PersistenceException
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException
当我进行个人测试时,我得到了
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [person]
...
缺少什么?