1 <property name="hibernateProperties">
2 <props>
3 <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
4 <prop key="hibernate.show_sql">false</prop>
5 <!-- Create/update the database tables automatically when the JVM starts up
6 <prop key="hibernate.hbm2ddl.auto">update</prop> -->
7 <!-- Turn batching off for better error messages under PostgreSQL
8 <prop key="hibernate.jdbc.batch_size">100</prop> -->
9 <prop key="hibernate.jdbc.batch_size">50</prop>
10 </props>
11 </property>
The larger the Fetch Size is set, the fewer times the database is read and the faster the speed is; the smaller the Fetch Size is, the more times the database is read and the slower the speed is.
2. If it is a very large system, it is recommended to generate htm files. Speed up page promotion.
3. Don’t put all the responsibility on hibernate, refactor the code, reduce operations on the database, try to avoid using in operations during database queries, and avoid recursive query operations. The code quality and the rationality of the system design determine the system. Performance level.
4. When querying large amounts of data, use list() or iterator() with caution to return query results.
(1). When using List() to return results, Hibernate will initialize all query results into persistent objects. When the result set is large, it will take up a lot of processing time.
(2). When using iterator() to return results, Hibernate will call the query to initialize the corresponding object each time iterator.next() is called to return the object and use the object. For large amounts of data, each query will be called. Spend more time. It is advantageous to use iterator() when the result set is large, but contains a large amount of the same data, or when not all of the result set will be used.
5. In one-to-many and many-to-one relationships, using the delayed loading mechanism will cause many objects to be initialized when they are used. This can save memory space and reduce the load on the database, and if the collection in PO When not in use, mutual database interactions can be reduced and processing time reduced.
6. When there is an associated PO (persistent object), if default-cascade="all" or "save-update" is used, when adding a new PO, please pay attention to the assignment operation of the collection in the PO, because it may cause multiple Perform an update operation.
7. For operations such as adding, modifying, and deleting large amounts of data or querying large amounts of data, the number of interactions with the database is the most important factor that determines the processing time. Reducing the number of interactions is the best way to improve efficiency, so in During the development process, please set show_sql to true, have a deep understanding of Hibernate's processing process, and try different methods to improve efficiency. Try to display each page as much as possible and reduce the operations on the database to less than 100-150 items. The less the better.
The above are some thoughts on hibernate performance optimization during project development with struts+hibernate+spring.