通常我将我的 UUID 作为字符串存储到数据库中。在 Spring Boot 2.x 中,我曾经用
@Type(type = "org.hibernate.type.UUIDCharType")
装饰 UUID。不知何故在 Spring Boot 3.x 中它不再起作用了。它告诉我Cannot resolve method 'type'
.
我知道雅加达有一些变化,但我不知道这对我来说是否是个问题。
我的实体:
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;
import java.util.Set;
import java.util.UUID;
@Data
@Entity
@Table(name = "werkstatt")
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class WerkstattEntity {
@Id
@Column(columnDefinition = "VARCHAR(255)")
@Type(type = "org.hibernate.type.UUIDCharType")
private UUID id;
}
我的 gradle 部门:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.springframework.security:spring-security-test'
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-api
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-impl
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-jackson
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
implementation 'org.mapstruct:mapstruct:1.5.5.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final'
}