Hibernate Tutorial 11

Suppose that we are planning a promotion for the Hibernate books in our online bookshop. All the books having the word “Hibernate” in the name will have 10 dollars discount. | Hibernate Tutorial 11 Batch Processing and Native SQL By Gary Mak hibernatetutorials@ September 2006 1. Batch processing with HQL Suppose that we are planning a promotion for the Hibernate books in our online bookshop. All the books having the word Hibernate in the name will have 10 dollars discount. According to what we have learned from the previous tutorials we could do it by querying the matched books first and then update them one by one. Session session Transaction tx null try tx Query query from Book where name like 0 Hibernate List books for Iterator iter Book book Book new Integer .intValue - 10 book catch HibernateException e if tx null throw e finally It can be easily noticed that this kind of update is very ineffective. If using SQL we can write a single update statement for this task. Fortunately HQL can also support this kind of batch update. Remember that it should be property names occurred in HQL statements not column names. Session session Transaction tx null try tx Query query update Book set price price - where name like 0 10 1 Hibernate int count Page 1 of 6 catch HibernateException e if tx null throw e finally In addition to batch update HQL can also support batch delete. Notice that the from keyword in the delete statement is optional. Session session Transaction tx null try tx Query query delete from Book where name like 0 Hibernate int count catch HibernateException e if tx null throw e finally 2. Querying with native SQL In .

Không thể tạo bản xem trước, hãy bấm tải xuống
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.