Spring Data JDBC 报错 After saving the identifier must not be null

Spring Boot JDBC About 826 words

错误信息

java.lang.IllegalArgumentException: After saving the identifier must not be null
    at org.springframework.util.Assert.notNull(Assert.java:204)
    at org.springframework.data.jdbc.core.JdbcAggregateTemplate.afterExecute(JdbcAggregateTemplate.java:399)
    at org.springframework.data.jdbc.core.JdbcAggregateTemplate.performSave(JdbcAggregateTemplate.java:441)
    at org.springframework.data.jdbc.core.JdbcAggregateTemplate.save(JdbcAggregateTemplate.java:167)
    at org.springframework.data.jdbc.repository.support.SimpleJdbcRepository.save(SimpleJdbcRepository.java:68)

解决方法

添加Spring提供的@Id注解,指定字段为主键。

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;

@Data
@Table(name = "link")
public class Link {

    @Id
    private Integer id;

}
Views: 679 · Posted: 2024-04-15

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh