其他分享
首页 > 其他分享> > ids for this class must be manually assigned before calling save(): com.jia.enity.Book;

ids for this class must be manually assigned before calling save(): com.jia.enity.Book;

作者:互联网

报错:

ids for this class must be manually assigned before calling save(): com.jia.enity.Book; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.jia.enity.Book

解决办法:
因为数据中的数据id是自增的,测试的时候没有写id,要在实体类上加上注解
@GeneratedValue(strategy = GenerationType.IDENTITY)

   @Test
    void save(){
        Book book = new Book();
        book.setName("spring boot");
        book.setAuthor("李四");
        Book book1 = bookRepository.save(book);
        System.out.println(book1);

    }
@Entity
@Data
public class Book {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String name;
    private String author;

}

标签:enity,manually,class,id,Book,save,book
来源: https://blog.csdn.net/weixin_44591656/article/details/122726975