我有一个表格帖子,其评级与@OneToMany有关:
class Post {
@OneToMany
List<Rating> rating;
}
如何在不阅读珍贵评级的情况下保存新评级?
答案 0 :(得分:0)
您可以为Repository
实体创建Rating
并仅保存评级
public interface RatingRepository extends JpaRepository<Rating, Long> {
}
并在您的bean中注入此存储库并调用ratingRepository.save()
Rating rating = new Rating();
rating.setPost(post);
//...
ratingRepository.save(rating);