ILyaCyclone icon

Untitled

ILyaCyclone | PRO | 04/16/19 11:25:18 AM UTC | 0 ⭐ | 671 👁️ | Never ⏰ | []
Java |

1.96 KB

|

None

|

0 👍

/

0 👎

// ------------------- ТЕСТ -------------------
@Test
void testUpdate() {
        Comment updatedComment = new Comment(...);
        commentRepository.save(updatedComment);
 
        Comment actual = commentRepository.findOne(updatedComment.getCommentId());
 
        assertThat(actual).isEqualToIgnoringGivenFields(updatedComment, "book"); // игнорируем book, чтобы программа не вошла в бесконечный цикл book-comment-book-comment-...
 
       // до сюда всё хорошо, теперь отдельно проверяем book, игнорируя comments 
        assertThat(actual.getBook()).isEqualToIgnoringGivenFields(updatedComment.getBook(), "comments"); // здесь ошибка Cannot locate field $$_hibernate_interceptor on class model.Book
    }
 
// ------------------- КНИЖКА -------------------
@Entity
@Table(name = "book")
@Data
@NoArgsConstructor
public class Book {
    @Id
    @GeneratedValue(strategy = IDENTITY)
    private Long bookId;
 
    private String title;
    private Integer year;
 
    @ManyToOne
    @JoinColumn(name = "author_id", nullable = false)
    private Author author;
    @ManyToOne
    @JoinColumn(name = "genre_id", nullable = false)
    private Genre genre;
 
    @OneToMany(
            mappedBy = "book",
            cascade = CascadeType.ALL,
            orphanRemoval = true
    )
    private List<Comment> comments = new ArrayList<>();
    // конструктор...
}
 
// ------------------- КОММЕНТ -------------------
@Entity
@Table(name = "comment")
@Data
@NoArgsConstructor
public class Comment {
    @Id
    @GeneratedValue(strategy = IDENTITY)
    private Long commentId;
 
    private String commentator;
    private String text;
    private LocalDateTime date;
 
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "book_id", nullable = false)
    private Book book;
 
    // конструктор...
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎