Formula
(from : http://weishuwei.iteye.com/blog/68030)
1,formula ="()",里面的是sql语句,字段和表名都应该和数据库相应,而不是字段,若带有参数如cur.id= currencyID,这个currencyID才是对象的东东.
2,formula ="( sql )",这个括号不能少,不然会报错,我试了几次,没括号就报错,添上就没问题
3,操作字段一定要用别名
(from:http://www.cnblogs.com/iloveu/archive/2009/01/20/1378810.html)
* formula公式里的字段都是数据库里的字段名,除了查询条件参数是要和配置文件里的字段匹配。
(from:http://zhiweiv.iteye.com/blog/361525)
这下子对于formula里的sql语句为什么必须放在括号里应该明白了,因为formula里面的值会作为一条sql语句select和from之间的内容,我们把sql语句放到括号里实际上就是做为一条子查询执行!!! 例如最开始示例的的rank对应的sql语句就应如下样子
dynamic-update
- when true, dynamic generate sql, if any changes for the property, it will appear in update sql, otherwise, wont be included.
dynamic-insert
- when true, insert will dynamic generate sql, if the property is NOT null, it will be included in SQL, otherwise, wont.
lazy-loading
1. If no record in database, still lazy-load uninitialized object.
2. only throw exception when call method of the proxy object
3. when access ID: getID(). wont trigger any database query
Hibernate performance
1. lazy-loading
2. batch-size: the size of elements to retrieve each time
3. one-to-one & many-to-one, better use outer-join to fetch data, it will reduce query times.
4. max-fetch-depth: outer join tables depths...
Join Query
1. hibernate configure: outer-join="true", sql will be left outer join
2. HQL e.g. Person has items, "from Person p inner join p.items" No "on" like the one in SQL
3. SQL, we have "select xxx inner join xxx ON...."
4. HQL join will return a list of array which contains joined objects. e.g. "from customer c left outer join c.order"; if we only want customer, we can use "Select c from customer c left outer join c.order"
5. HQL join fetch will get first object and load second fetch object as reference
6. inner-join & outer-join , result is all arrays which contains joined objects
HQL & Criteria
* hql will check whether passed object has map or not
* criteria will load all implementor of given class.
* check field null using "is null", not "=null" which wont get any result (might has grammar error)
Implict Join applys to "Many-to-one" and "one-to-one" relationship. Not "One-to-Many"
left/right (outer) join : outer can be omited
Hibernate configure
use_query_cache=true, is not enought, need set Query.setCachable("true")
Query or Criteria result
1. If more than one result return, need use setMaxResult() to restrict output and then use uniqueResult
Criterial #Expression #Order
分享到:
相关推荐
2. **简化开发流程**:Hibernate提供了一系列高级特性,如缓存机制、查询语言(HQL)等,极大地简化了数据库操作的过程。 3. **强大的持久化功能**:支持集合、复合类型等复杂数据结构的持久化,同时还提供了用户...
文件已上传到百度网盘,附件中是下载地址。... Hibernate-A.Developer's.Notebook—Hibernate程序高手秘笈 [美] james elliott(著) | o'reilly taiwan公司编译(译) | 东南大学出版社 | 9787564106379 |
结语 2. 体系结构 2.1. 总览 2.2. JMX集成 2.3. JCA支持 3. SessionFactory配置 3.1. 可编程配置方式 3.2. 获取SessionFactory 3.3. 用户自行提供JDBC连接 3.4. Hibernate提供的JDBC...
最后,推荐的Hibernate相关书籍可以帮助深入理解和掌握框架,例如《Hibernate in Action》和《Hibernate Tips: More than 70 solutions to common Hibernate problems》等,这些书籍通常会详细讲解Hibernate的基础...
14.15. Tips & Tricks 15. Criteria Queries 15.1. Creating a Criteria instance 15.2. Narrowing the result set 15.3. Ordering the results 15.4. Associations 15.5. Dynamic association fetching 15.6. ...
结语 2. 体系结构 2.1. 总览 2.2. JMX集成 2.3. JCA支持 3. SessionFactory配置 3.1. 可编程配置方式 3.2. 获取SessionFactory 3.3. 用户自行提供JDBC连接 3.4. Hibernate提供的JDBC...
Struts 2 Tips Struts 2 是一个流行的开源 MVC(模型-视图-控制器)框架,用于构建Java Web应用程序。这个框架极大地简化了企业级Web应用的开发,提供了丰富的特性,如动作映射、结果类型、拦截器、插件等。在本文...
In addition, this book contains well separated, subjective material (opinion sidebars), comic illustrations, tips and tricks, all of which provide real-world and practical perspectives on relevant ...
In addition, this book contains well separated, subjective material (opinion sidebars), comic illustrations, tips and tricks, all of which provide real-world and practical perspectives on relevant ...
19. **JPA与Hibernate**:Java持久层API(JPA)和Hibernate是ORM(对象关系映射)工具,简化了数据库操作。 20. **Java性能调优**:包括JConsole、VisualVM等工具的使用,以及对内存、CPU、GC的监控和优化。 以上...
2. **类与对象**:深入理解面向对象编程,如封装、继承和多态,以及如何设计和实现类。 3. **接口与抽象类**:学习如何使用接口来定义行为规范,以及何时使用抽象类来实现代码复用。 4. **集合框架**:熟悉...
The tone of the book is intended to be light rather than pedantic and hints and tips based on the author’s life experience are included. Table of Contents Chapter 1 Stuff You Need to Know Chapter 2 ...
Spring-Hibernate-示例使用 Spring、Hibernate、Gradle、Eclipse、Tomcat、Mysql 的 Java Web 应用程序框架。 ##tips 如果您正在构建一个 web 应用程序,请确保您应用 'eclipse-wtp' 插件而不是 'eclipse'。
2. **启动与停止服务器** - 使用命令行工具`bin/server start serverName`启动服务器,`serverName`是你的服务器实例名。 - 使用`bin/server stop serverName`来停止服务器。 3. **部署应用** - 将Java EE或...
2 jcs学习笔记 3 关于Hibernate的Cache问题 4 用缓冲技术提高JSP应用的性能和稳定性 5 SwarmCache入门 <br> 源代码研究 1 Jive中的全局配置 2 Jive源代码情景分析-index....
This chapter focuses on using XDoclet for data persistence, including ORM frameworks like Hibernate. Key topics include: - **Data Persistence Overview**: An introduction to data persistence in Java ...