Play中JPA Support的一些查询

Find by ID:
Post aPost = Post.findById(5L);

Find all:
List<Post> posts = Post.findAll();
List<Post> posts = Post.all().fetch();
List<Post> posts = Post.all().fetch(100); 
List<Post> posts = Post.all().from(50).fetch(100);

简化查询:
Post.find("byTitle", "My first post").fetch();
Post.find("byTitleLike", "%hello%").fetch();
Post.find("byAuthorIsNull").fetch();
Post.find("byTitleLikeAndAuthor", "%hello%", connectedUser).fetch();

使用 JPQL 查询:
Post.find(
    "select p from Post p, Comment c where c.post = p and c.subject like ?", "%hop%"
         );

Post.find("title", "My first post").fetch();
Post.find("title like ?", "%hello%").fetch();
Post.find("author is null").fetch();
Post.find("title like % and author is null", "%hello%").fetch();
Post.find("title like % and author is null order by postDate", "%hello%").fetch();

Post.find("order by postDate desc").fetch();


计算对象个数:
long postCount = Post.count();
long userPostCount = Post.count("author = ?", connectedUser);


你可能感兴趣的:(C++,c,jpa,C#)