@Test
  public void test() {

    doInJPA(
        entityManager -> {
          Post post = new Post();
          post.setId(1L);
          post.setTitle("High-Performance Java Persistence");
          entityManager.persist(post);
        });
    doInJPA(
        entityManager -> {
          Post post = entityManager.find(Post.class, 1L);
          LOGGER.info("Fetched post: {}", post);
          post.setScore(12);
        });
  }
Пример #2
0
 public List<Post> news() {
   return Post.find(
           "SELECT p FROM Post p, IN(p.author.friendedBy) u WHERE u.from.id = ?1 and (U.accepted = true or u.to.id = ?1) order by p.updatedAt desc",
           this.id)
       .fetch();
 }
Пример #3
0
 /* Checks if a comment belongs to this Post or to its root post
 RECURSIVE untill no rootPost encountered
 invoced in blog.scala.html */
 public boolean belongsToComment(Comment c) {
   if (c.post.equals(this)) return true;
   if (rootPost == null) return false;
   if (rootPost.belongsToComment(c)) return true;
   return false;
 }