놀이방 프레임 워크의 Yet Another Blog Engine example가 어린이 댓글과 게시물 클래스 : 데이터가 .yml에 의해 채워집니다Play 프레임 워크에서 @OneToMany 목록은 언제 채워 집니까?
// Post.java
// ... other fields, etc.
@OneToMany(mappedBy="post", cascade=CascadeType.ALL)
public List<Comment> comments;
// ...
이 모든 것이 잘 작동하는 것 같다 :
// BasicTest.java
@Test
public void fullTest() {
Fixtures.load("data.yml");
// ...
// Find the most recent post
Post frontPost = Post.find("order by postedAt desc").first();
assertNotNull(frontPost);
// ...
// Check that this post has two comments
assertEquals(2, frontPost.comments.size()); // succeeds
}
그러나 수동으로 포스트와 데이터베이스에 대한 일부 의견을 저장할 때 frontPost.comments 필드는 비어 있습니다 :
@Test
public void myFullTest() {
// Fixtures.load("data.yml");
User u = new User("[email protected]", "secret", "Bob").save();
Post p = new Post(u, "About the model layer", "The model has a central position in a Play! application. It is the ...").save();
Comment c1 = new Comment(p, "Guest", "You are right !").save();
Comment c2 = new Comment(p, "Mike", "I knew that ...").save();
// Find the most recent post
Post frontPost = Post.find("order by postedAt desc").first();
// This assertion fails as frontPost.comments is empty:
// "Failure, expected:<2> but was <0>"
assertEquals(2, frontPost.comments.size());
}
는 왜 이런 일이 일어나는가, 그리고 어떻게 하나 하나의 클래스를 저장할 때 JPA가 Post.comments 필드를 채울 만들 수 있습니까?
감사합니다.
업데이트 : 해결책은 find (....) 호출 전에 JPA.em(). clear()를 호출하는 것이 었습니다.
감사합니다. JPA.em(). clear()를 사용하여 Hibernate 캐시를 지우고 개체를 DB에서 강제로 가져와야 함을 알았습니다. – tba