. Trong những trường hợp này, bạn có thể tạo một bộ lọc Hibernate để loại bỏ các dữ liệu không mong muốn. Bộ lọc cung cấp một cách để ứng dụng của bạn để hạn chế kết quả của một truy vấn dữ liệu qua các tiêu chuẩn của bộ lọc. | CHAPTER 8 USING THE SESSION 189 public static void main String argv Creating test user. createUser test Proceeding to main test. Session s1 Session s2 try Update 1 Query q1 from Publisher Publisher pub1 Publisher jeff Update 2 Query q2 from Subscriber Subscriber sub1 Subscriber dave Update 3 Query q3 from Subscriber Subscriber sub2 Subscriber jeff Update 4 Query q4 from Publisher Publisher pub2 Publisher dave .commit .commit catch RuntimeException e1 Run the boilerplate to roll back the sessions rollback s1 rollback s2 throw e1 finally 190 CHAPTER 8 USING THE SESSION Run the boilerplate to close the sessions close sl close s2 Caching Accessing a database is an expensive operation even for a simple query. The request has to be sent usually over the network to the server. The database server may have to compile the SQL into a query plan. The query plan has to be run and is limited largely by disk performance. The resulting data has to be shuttled back again usually across the network to the client and only then can the application program begin to process the results. Most good databases will cache the results of a query if it is run multiple times eliminating the disk I O and query compilation time but this will be of limited value if there are large numbers of clients making substantially different requests. Even if the cache generally holds the results the time taken to transmit the information across the network is often the larger part of the delay. Some applications will be able to take .