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

huangapple go评论75阅读模式
英文:

cannot find symbol @Type(type = "list-array")error when upgrade to spring boot 3

问题

以下是我的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',并将Hibernate升级为'com.vladmihalcea:hibernate-types-55:2.20.0'。我本地的Gradle版本是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

希望这对您有帮助。

英文:

Below is my build.gradle file

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

below is my entity class,

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 = &quot;students_stored_row&quot;)
@Entity(name = &quot;studentDAO&quot;)
public class StudentDAO {

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

I have recently upgraded the spring boot version to springBootVersion = '3.0.2' and hibernate to 'com.vladmihalcea:hibernate-types-55:2.20.0'. Gradle version in my local : gradle-7.4.1. Upon running the ./gradlew clean build I observed the below error,

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

 error: cannot find symbol
    @Type(type = &quot;list-array&quot;)
          ^
  symbol:   method type()
  location: @interface Type

答案1

得分: 0

现在根据文档,您需要在实现UserType接口的类中使用value参数:
https://docs.jboss.org/hibernate/orm/6.0/javadocs/org/hibernate/annotations/Type.html

英文:

Now you need to use value parameter with class implementing the UserType interface as per documentation:
https://docs.jboss.org/hibernate/orm/6.0/javadocs/org/hibernate/annotations/Type.html

答案2

得分: 0

尝试这个:

@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;
}
英文:

try this :

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

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

huangapple
  • 本文由 发表于 2023年2月24日 16:04:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75553978.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定