【文档摘要】J2EE Persistence - Introduction to the Java Persistence API【Querying Entities】
来源:互联网 发布:网络借钱平台 编辑:程序博客网 时间:2024/05/21 13:25
JPQL (Java Persistence Query Language):JPQL并非类型安全,需要做类型转换,但是JPQL更加类似SQL,比起Criteria API来说,它更加可读。
JPQL Dynamic Query?(这个和J2EE文档解释是否相符?)
@PersistenceContext(unitName="dq")
EntityManager em;
public long queryFinancialRecordsOfDept(String deptName, String companyName) {
String query = "SELECT d.records " +
"FROM Department d " +
"WHERE d.name = '" + deptName +
"' AND " +
" d.company.name = '" + companyName + "'";
return em.createQuery(query, Long.class).getSingleResult();
}
因为Query是每次生成,每次都可可能不一样,所以很难做cache。效率相对比较低。
Criteria API(typesafe):Criteria API比起Dynamic JPQL来说,性能更好。因为Dynamic JPQL每次都需要做解析。同时Criteria API是类型安全的,不需要做类型转换。但是比起JPQL来说使用起来更加繁琐。
参考资料:
http://www.kumaranuj.com/2013/06/jpa-2-dynamic-queries-vs-named-queries.html
https://docs.oracle.com/javaee/7/tutorial/doc/persistence-intro004.htm#GJISE
- 【文档摘要】J2EE Persistence - Introduction to the Java Persistence API【Querying Entities】
- 【文档摘要】J2EE Persistence - Introduction to the Java Persistence API【Entities】
- 【文档摘要】J2EE Persistence - Introduction to the Java Persistence API【Entities Inheritance】
- 【文档摘要】J2EE Persistence - Introduction to the Java Persistence API【Managing Entities】
- 【文档摘要】J2EE Persistence - Controlling Concurrent Access to Entity Data with Locking
- Introduction to using Java Persistence API in a web application in Java EE environment
- JPA-Java Persistence API
- Java Persistence API
- Java Persistence Api
- JPA-Java Persistence API
- Combining Groovy, Grails, MySQL, and the Java Persistence API
- JPA 全称Java Persistence API
- JPA注解 Java Persistence API
- JPA (Java Persistence API)概述
- JPA (Java Persistence API)概述
- Persistence in the Enterprise: A Guide to Persistence Technologies
- Java persistence with hibernate concept 3 -- Mapping entities with identity
- persistence
- 为什么默认配置下嵌套的VMware vSphere/ESXi上安装的虚拟机网络连接失败?
- spring 中log4j的配置
- 浅谈安全事件响应
- Coursera台大机器学习基础课程学习笔记1 -- 机器学习定义及PLA算法
- self.navigationItem 与 self.navigationController.navigationItem 的区别
- 【文档摘要】J2EE Persistence - Introduction to the Java Persistence API【Querying Entities】
- Python 第一章 基础知识(7) 模块
- POJ-2723(2-SAT)
- 关于聚类算法BIRCH
- [LeetCode] Add Two Numbers
- windows下arp命令
- linux shell
- 如何解决每次打开office2010都会出现正在配置
- How To Validate ASM Diskgroup Consistency/State After ASM Reclamation Utility (ASRU) Execution Abort