1. 关于session
1) 什么时机对session进行打开和关闭?
首先,别用session-per-operation这种反模式了,也就是说,在单个线程中, 不要因为一次简单的数据库调
用,就打开和关闭一次Session
!数据库事务也是如此。
最好的模式是:
①session-per-request模式,所有载入的实例在用户思考的过程 中都处于与Session脱离的状态。
②session-per-conversation模式,当一个新的客户端请求到来的时候,它又重新连接上底层的JDBC连接。
2) 关于session要注意的问题。
Session 缓存了处于持久化状态的每个对象(Hibernate会监视和检查脏数据)。 这意味着,如果你让Session打开很长一段时间,或是仅仅载入了过多的数据, Session占用的内存会一直增长,直到抛出OutOfMemoryException异常。
当异常发生的时候,必须要回滚 Transaction ,关闭Session。如果你不这样做的话,Hibernate无法保证内存状态精确的反应持久状态。
2. 关于映射关联
对映射关联要注意的问题:
实际上,我们认为绝大多数的连接是一对多和多对一的,你应该谨慎使用其它连接风格,用之前问自己一句,是否真的必须这么做。单向关联更加难于查询。在大型应用中,几乎所有的关联必须在查询中可以双向导航。
对于关联表不要设置级联删除,而是设置级联的约束或者no action,让应用去手动删除.
分享到:
相关推荐
Hibernate A Developer‘s NotebookHibernate A Developer‘s Notebook
hibernate 资料hibernate 资料hibernate 资料hibernate 资料
hibernate3hibernate3hibernate3hibernate3hibernate3hibernate3hibernate3hibernate3
hibernate教程hibernate教程hibernate教程
hibernate annotation hibernate3
hibernate5 hibernate PDF 讲义 动力 hibernate ssh hibernate5 节点
hibernate 5.2.15 hibernate 5.2.15 hibernate 5.2.15 hibernate 5.2.15 hibernate 5.2.15hibernate 5.2.15
Hibernate.jar包,Hibernate可以应用在任何使用JDBC的场合,包含 hibernate-commons-annotations-4.0.1.Final.jar hibernate-core-4.1.12.Final.jar hibernate-ehcache-4.1.12.Final.jar hibernate-entitymanager-...
All possible basic and advanced Hibernate mappings are shown in this book, with hundreds of examples in Hibernate's XML format, including Java Persistence annotations for JDK 5.0. Readers can get ...
It’s also a testament to the quality of specifications and tools available, which today make it easy to start a project and to estimate and reduce risk when building large, complex application
hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,包含4个说明文档,分别详细解说了hibernate...
hibernate 实战 hibernate 实战 hibernate 实战 hibernate 实战
hibernate第一个hibernate
Hibernate面试题专栏 - 最全的Hibernate面试题, Hibernate笔试题, Hibernate问题 Hibernate教程
HIBERNATE HIBERNATE HIBERNATE HIBERNATE
使用Hibernate的JPA实例,包含jar文件
Hibernate A J2EE Developer's Guide
hibernate aiphibernate aiphibernate aip
hibernate
Search but also uncovering some of the background behind Hibernate Search’s design. We will start by describing full-text search technology and why this tool is invaluable in your development toolbox...