Hibernate optimization

xiaoxiao2021-03-06  42

Hibernate optimization

Session Control To avoid the overhead created by Session, you need to control the current behavior of the Session: Controlling the use of Threadlocal Creating the Session Creating and closing the SESSION SESSION Nothing Filter Transaction Control For Hibernate by three DAO operation Find Save Flush Find is not need to open a business, so you can consider whether you don't use transaction control for SaveorupDate. Using transaction is now done in the end of Filter, but there is no need in some action, frequent switching transactions may bring A certain system overhead current test uses and does not use the transaction to query the test results (according to ID query record 100 times time comparison) Do not open the transaction 421ms Open transaction 516ms transaction Switch is best limited to the method, can consider switching transactions in the service method When this problem session shutdown and transaction, Hibernate actively calls the Flush method to synchronize, so do not need to care for the Flush method in the current project, the use of JDBC transaction does not choose JTA as a transaction to achieve the right to abandon the current test server tomcat itself is just a web server, it does not support the benefits of jta hibernate configuration property information hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory net.sf.hibernate.transaction.JDBCTransactionFactory jta the JTA provides the inter-Session Transaction management capabilities have left the selection space to make a single increase in selection. Unnewhere is not required to call session.BegIntransAction (). Method for multiple records to call the API UserTransaction UT = (NEW INITIALCONTEXT () .lookup ("java: comp / userTransaction)); ut.begin (); // ..... UT. Commit (); using the following manner, transaction control can also be achieved, but because Hibernate also calls the above API implementation, it is not recommended to use Transaction TX = session.begintransAction (); tx.commit (); You can consider the use of Spring's AOP implementation replace the current implementation in Tomcat Cache in the Hibernate map file to specify each mapping entity cache Strategy Configuring CAC After He, Hibernate automatically applies the Cache mechanism for the selection policy query.list () for the query method for the query method. Returns all object Query.Iterate (); and the IteRate method, you first get all through a SELECT SQL Get all The ID of the record of the query condition is again looped to this ID collection, and then fill in the records corresponding to each ID after retrieving the records corresponding to each ID. However, the List method does not read the data from the cache and the Iterator method will read the data for each record after returning the ID collection.

转载请注明原文地址:https://www.9cbs.com/read-51800.html

New Post(0)