利用JPA命名查询 [英] utilizing JPA Named Queries
本文介绍了利用JPA命名查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我从NetBeans中的数据库创建Entity类时,它为我提供了从持久字段创建命名查询的选项.因此,我在Entity类的顶部看到了这些命名查询.
When I create an Entity class from a database in NetBeans, it gives me the option to create Named Queries from persistent fields. Accordingly, I see these named queries listed at the top of my Entity class.
这些查询究竟是什么,如何利用/调用"它们?
What exactly are these queries, and how can I utilize/"call" them?
我知道这个问题比SO上的问题更笼统,因此我很乐意接受指向回答这些问题的教程的链接,但我一直找不到自己.
I'm aware this question is more general than is preferred on SO, so I'm happy to accept a link to a tutorial that answers these questions, but I've been unable to find one myself.
推荐答案
请参见
如果您有:
@NamedQuery(name="Country.findAll", query="SELECT c FROM Country c")
public class Country {
...
}
用于:
TypedQuery<Country> query = em.createNamedQuery("Country.findAll",Country.class);
List<Country> results = query.getResultList();
另请参阅:
- Annotation Type NamedQuery
- Tutorial: Build a Web Application (JSF) Using JPA
这篇关于利用JPA命名查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文