Hibernate最佳实践(Best Practices)
2007-06-04 11:28
369 查看
1、 使用Configuration装载映射文件时,不要使用绝对路径装载。最好的方式是通过getResourceAsStream()装载映射文件,这样Hibernate会从classpath中寻找已配置的映射文件。
2、 SessionFactory的创建非常消耗资源,整个应用一般只要一个SessionFactory就够了,只有多个数据库的时候才会使用多个SessionFactory。
3、 在整个应用中,Session和事务应该能够统一管理。(Spring为Hibernate提供了非常好的支持)
4、 将所有的集合属性配置设置为懒加载(lazy="true")。在hibernate2.x版本中,lazy默认值是"false",但hibernate3.x已经将lazy的默认改为"true"了。
5、 在定义关联关系时,集合首选Set,如果集合中的实体存在重复,则选择List(在定义配置文件时,可以将List定义为bag),数组的性能最差。
6、 HQL子句本身大小写无关,但是其中出现的类名和属性名必须注意大小写区分。
7、 在一对多的双向关联中,一般将集合的inverse属性设为true,让集合的对方维护关联关系。例如:Group-User,由User来维护Group和User的关联关系。
8、 在非分布式架构中,不需要使用DTO来向上层传输数据。直接使用POJO的Entity就可以了。
在<many-to-one>中,将outer-join 设置为false。If the SQL statements use join operations that are too complex and
slow, set outer-join to false for <many-to-one> associations (this is
enabled by default). Also try to tune with the global hibernate.
max_fetch_depth configuration option, but keep in mind that this
is best left at a value between 1 and 4.
9、 如果要精通Hibernate,熟练掌握关系数据库理论和SQL是前提。
10、
If the SQL statements use join operations that are too complex and
slow, set outer-join to false for <many-to-one> associations (this is
enabled by default). Also try to tune with the global hibernate.
max_fetch_depth configuration option, but keep in mind that this
is best left at a value between 1 and 4.
2、 SessionFactory的创建非常消耗资源,整个应用一般只要一个SessionFactory就够了,只有多个数据库的时候才会使用多个SessionFactory。
3、 在整个应用中,Session和事务应该能够统一管理。(Spring为Hibernate提供了非常好的支持)
4、 将所有的集合属性配置设置为懒加载(lazy="true")。在hibernate2.x版本中,lazy默认值是"false",但hibernate3.x已经将lazy的默认改为"true"了。
5、 在定义关联关系时,集合首选Set,如果集合中的实体存在重复,则选择List(在定义配置文件时,可以将List定义为bag),数组的性能最差。
6、 HQL子句本身大小写无关,但是其中出现的类名和属性名必须注意大小写区分。
7、 在一对多的双向关联中,一般将集合的inverse属性设为true,让集合的对方维护关联关系。例如:Group-User,由User来维护Group和User的关联关系。
8、 在非分布式架构中,不需要使用DTO来向上层传输数据。直接使用POJO的Entity就可以了。
在<many-to-one>中,将outer-join 设置为false。If the SQL statements use join operations that are too complex and
slow, set outer-join to false for <many-to-one> associations (this is
enabled by default). Also try to tune with the global hibernate.
max_fetch_depth configuration option, but keep in mind that this
is best left at a value between 1 and 4.
9、 如果要精通Hibernate,熟练掌握关系数据库理论和SQL是前提。
10、
If the SQL statements use join operations that are too complex and
slow, set outer-join to false for <many-to-one> associations (this is
enabled by default). Also try to tune with the global hibernate.
max_fetch_depth configuration option, but keep in mind that this
is best left at a value between 1 and 4.
相关文章推荐
- Hibernate 最佳实践(Best Practices)
- Hibernate 最佳实践(Best Practices)
- atitit. 统计功能框架的最佳实践(1)---- on hibernate criteria
- ASP.NET&Spring.NET&NHibernate最佳实践(一)——目录
- ASP.NET&Spring.NET&NHibernate最佳实践(九)——第4章权限子系统(2)
- ASP.NET&Spring.NET&NHibernate最佳实践(十七)——第4章权限子系统(10)
- ASP.NET&Spring.NET&NHibernate最佳实践(二十二)——第4章权限子系统(15)
- 关于HIbernate在dao层的最佳实践。
- 最佳实践(Best Practices)
- Hibernate二级缓存 ---- 最佳实践
- Struts2、Spring、Hibernate 高效开发的最佳实践
- Hibernate二级缓存 ---- 最佳实践
- atitit. 统计功能框架的最佳实践(1)---- on hibernate criteria
- CUDA C最佳实践-CUDA Best Practices(一)
- CUDA C最佳实践-CUDA Best Practices(二)
- ASP.NET&Spring.NET&NHibernate最佳实践(二)——第1章前言
- ASP.NET&Spring.NET&NHibernate最佳实践(七)——第3章人事子系统(4)人事子系统小结
- ASP.NET&Spring.NET&NHibernate最佳实践(十)——第4章权限子系统(3)
- ASP.NET&Spring.NET&NHibernate最佳实践(二十三)——第4章权限子系统(16)
- Top 20+ MySQL Best Practices(20条MySQL最佳实践)