报错:
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;
}