TAILIEUCHUNG - manning Hibernate in Action phần 8

Tham khảo tài liệu 'manning hibernate in action phần 8', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Executing queries 249 setProperties matches the names of JavaBean properties to named parameters in the query string using setParameter to guess the Hibernate type and bind the value. In practice this turns out to be less useful than it sounds since some common Hibernate types aren t guessable date in particular . The parameter-binding methods of Query are null-safe making this code legal from User as u where name .setString name null . list However the result of this code is almost certainly not what we intended. The resulting SQL will contain a comparison like username null which always evaluates to null in SQL ternary logic. Instead we must use the is null operator from User as u where is null .list So far the HQL code examples we ve shown all use embedded HQL query string literals. This isn t unreasonable for simple queries but once we start considering complex queries that must be split over multiple lines it starts to get a bit unwieldy. Using named queries We don t like to see HQL string literals scattered all over the Java code unless they re necessary. Hibernate lets you externalize query strings to the mapping metadata a technique that is called named queries. This allows you to store all queries related to a particular persistent class or a set of classes encapsulated with the other metadata of that class in an XML mapping file. The name of the query is used to call it from the application. The getNamedQuery method obtains a Query instance for a named query findItemsByDescription .setString description description . list In this example we execute the named query findItemsByDescription after binding a string argument to a named parameter. The named query is defined in mapping metadata . in using the query element query name findItemsByDescription CDATA from Item item where like description query Named queries don t have to be HQL .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.