Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java org.springframework.dao.EmptyResultDataAccessException:不存在id为x的类com.jea.user.user实体_Java_Spring Boot_Spring Security_Spring Data Jpa - Fatal编程技术网

Java org.springframework.dao.EmptyResultDataAccessException:不存在id为x的类com.jea.user.user实体

Java org.springframework.dao.EmptyResultDataAccessException:不存在id为x的类com.jea.user.user实体,java,spring-boot,spring-security,spring-data-jpa,Java,Spring Boot,Spring Security,Spring Data Jpa,问题 我在SpringBoot中有一个RESTAPI,带有JPA和SpringSecurity。当我尝试按ID删除数据库中的现有用户对象时,会收到以下错误消息: org.springframework.dao.EmptyResultDataAccessException: No class com.jea.user.User entity with id 3754c59a-20c5-4c6a-8ddd-62fc49809946 exists 作为路径变量提供给方法的ID与获取所有用户时返回的I

问题

我在SpringBoot中有一个RESTAPI,带有JPA和SpringSecurity。当我尝试按ID删除数据库中的现有用户对象时,会收到以下错误消息:

org.springframework.dao.EmptyResultDataAccessException: No class com.jea.user.User entity with id 3754c59a-20c5-4c6a-8ddd-62fc49809946 exists
作为路径变量提供给方法的ID与获取所有用户时返回的ID完全相同。 在我的Java模型中,ID保存为UUID,并在数据库中JPA创建一个二进制(255)列

下面是数据库中的我的JSON用户对象

{
    "id": "3754c59a-20c5-4c6a-8ddd-62fc49809946",
    "profilePicture": null,
    "username": "svennieboy",
    "password": "$2a$10$iZBq8gRsIPqYShu03qJ/2Ou4FWpRPMCs4kqrfo9zIcXozchR41yRC",
    "email": "s@live.nl",
    "role": "ROLE_USER",
    "location": null,
    "website": null,
    "biography": null,
    "allTweets": [],
    "recentTweets": [],
    "followers": [],
    "following": []
}
用户模型

@Entity
@Table(name = "account")
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private UUID id;

//Removed code for brevity
用户控制器方法

@DeleteMapping("/users/{id}")
    public ResponseEntity<String> deleteUser(@PathVariable UUID id) {
        userService.deleteUser(id);
        return new ResponseEntity<>("User deleted", HttpStatus.OK);
    }
 public void deleteUser(UUID id){
        userRepository.deleteById(id);
    }
用户存储库

public interface UserRepository extends CrudRepository<User, UUID> {
}
public interface UserRepository扩展了crudepository{
}

请告诉我出了什么问题,因为我不知道。

我在用户模型中将我的ID注释更改为这个,现在它可以工作了! 所以希望其他人会发现这个答案非常有用

@Entity
@Table(name = "account")
public class User {

    @Id
    @GeneratedValue( generator = "uuid2" )
    @GenericGenerator( name = "uuid2", strategy = "uuid2" )
    @Column( name = "id", columnDefinition = "BINARY(16)" )
    private UUID id;

我在用户模型中将我的ID注释更改为这个,现在它可以工作了! 所以希望其他人会发现这个答案非常有用

@Entity
@Table(name = "account")
public class User {

    @Id
    @GeneratedValue( generator = "uuid2" )
    @GenericGenerator( name = "uuid2", strategy = "uuid2" )
    @Column( name = "id", columnDefinition = "BINARY(16)" )
    private UUID id;

谢谢,对我也有用。你能解释一下为什么我们必须使用uuid2型发电机和通用型发电机吗?谢谢,我也能用。您能解释一下为什么我们必须将生成器类型uuid2与通用类型一起使用吗?