升级到spring Boot 3时,无法找到符号@Type(type =“list-array”)错误

41zrol4v  于 2023-03-02  发布在  Spring
关注(0)|答案(2)|浏览(239)

下面是我的build.gradle文件

buildscript {
    ext {
        springBootVersion = '3.0.2'
        springCloudVersion = '2022.0.0-M3'
    }
...
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa:3.0.0'
    implementation 'org.postgresql:postgresql:42.3.8'
    implementation 'com.vladmihalcea:hibernate-types-55:2.20.0'

下面是我的实体类,

import com.vladmihalcea.hibernate.type.array.ListArrayType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.jackson.Jacksonized;
import org.hibernate.annotations.Type;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Jacksonized
@Table(name = "students_stored_row")
@Entity(name = "studentDAO")
public class StudentDAO {

    @Id
    private String id;
    @Type(type = "list-array")
    @Column(name = "course", columnDefinition = "text[]")
    private List<String> courses;
    private List<String> coursePath;
    @Type(type = "jsonb")
    private List<Address> address;
 
}

我最近将Spring Boot 版本升级为springBootVersion = '3.0.2',将休眠版本升级为'com.vladmihalcea:hibernate-types-55:2.20.0'。gradle-7.4.1。在运行./gradlew clean build时,我观察到以下错误,

error: cannot find symbol
    @Type(type = "jsonb")
          ^
  symbol:   method type()
  location: @interface Type

 error: cannot find symbol
    @Type(type = "list-array")
          ^
  symbol:   method type()
  location: @interface Type
ttcibm8c

ttcibm8c1#

现在您需要使用value参数和类来实现UserType接口,如文档所示:https://docs.jboss.org/hibernate/orm/6.0/javadocs/org/hibernate/annotations/Type.html

ddrv8njm

ddrv8njm2#

试试这个:

@TypeDef(
    name = "list-array",
    typeClass = ListArrayType.class
)
public class StudentDAO {

    @Id
    private String id;
    @Type(type = "list-array")
    @Column(name = "course", columnDefinition = "text[]")
    private List<String> courses;
    private List<String> coursePath;
    @Type(type = "jsonb")
    private List<Address> address;
 
}

相关问题