英文:
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 = '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'
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 = "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;
}
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 = "jsonb")
^
symbol: method type()
location: @interface Type
error: cannot find symbol
@Type(type = "list-array")
^
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 = "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;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论