em.createQuery("select d from WikiDocument d where d.id = :id")
.setParameter("id", 6l)
.getSingleResult();
assert d.getName().equals("One");
WikiComment newComment = new WikiComment();
newComment.setAreaNumber(d.getAreaNumber());
newComment.setDerivedName(d);
newComment.setWikiname(WikiUtil.convertToWikiName(newComment.getName()));
newComment.setCreatedBy(em.find(User.class, 1l));
newComment.setSubject("Seven");
newComment.setContent("Testcomment Seven");
newComment.setUseWikiText(true);
newComment.setParent(d);
em.persist(newComment);
em.flush();
em.clear();
List<WikiComment> comments =
em.createQuery("select c from WikiComment c where c.parent = :doc order by c.createdOn asc")
.setParameter("doc", d)
.getResultList();
assert comments.size() == 7;
assert comments.get(0).getName().equals("One.Comment11967298211870");
assert comments.get(1).getSubject().equals("Two");
assert comments.get(2).getSubject().equals("Three");
assert comments.get(3).getSubject().equals("Four");
assert comments.get(4).getSubject().equals("Five");
assert comments.get(5).getSubject().equals("Six");
assert comments.get(6).getSubject().equals("Seven");
assert comments.get(6).getId().equals(newComment.getId());
}
}.run();
}