在java和hibernate中,当列是数组类型时,sql表创建失败

qco9c6ql  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(475)

在使用时创建表时,sql语句中出现语法错误 list-array 类型。

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "create table vehicle (id  serial not null, vehicle_types varchar[[*]] primary key (id))"; expected "(, FOR, UNSIGNED, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, AUTO_INCREMENT, BIGSERIAL, SERIAL, IDENTITY, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ,, )"; SQL statement:
create table vehicle (id  serial not null,  vehicle_types varchar[], primary key (id)) [42001-199]

我的表定义如下所示。

import com.vladmihalcea.hibernate.type.array.ListArrayType;

@Entity
@Table(name = "vehicle")
@EqualsAndHashCode(of = {"id", "created"})
@Getter
@Setter
@TypeDef(
        name = "list-array",
        typeClass = ListArrayType.class
)
public class Vehicle {

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   @JsonIgnore
   private Integer id;

   @Type(type = "list-array")
   @Column(
        name = "vehicle_types",
        columnDefinition = "varchar[]"
   )
   private List<String> vehicleTypes;

}

我有以下依赖性

<dependency>
    <groupId>com.vladmihalcea</groupId>
    <artifactId>hibernate-types-52</artifactId>
    <version>2.10.0</version>
</dependency>

我错过了什么?。

suzh9iv8

suzh9iv81#

修好了。
改变 columnDefinitionarrayvarchar[] ```
@Type(type = "list-array")
@Column(
name = "vehicle_types",
columnDefinition = "array"
)
private List vehicleTypes;

相关问题