TAILIEUCHUNG - Beginning Hibernate From Novice to Professional phần 4

Những chú thích này có thể được sử dụng kết hợp với, hoặc tại chỗ, một số các tập tin cấu hình mà các phiên bản trước của Hibernate yêu cầu. Những chú thích về bản chất là một EJB 3 tính năng này, mặc dù Hibernate cung cấp một số phần mở rộng độc quyền bổ sung. Trong Chương 6 chúng tôi thảo luận làm thế nào để sử dụng các chú thích này kiên trì. | 84 CHAPTER 5 AN OVERVIEW OF MAPPING The default in Hibernate 3 is that classes including collections like Set and Map should be lazily loaded. For example when an instance of the User class given in the next listing is loaded from the database the only fields initialized will be userid and username. public class User int userid String username EmailAddress emailAddress Set roles However as long as the object is still associated with Hibernate in the appropriate way see Chapter 9 the appropriate objects for emailAddress and roles will be loaded from the database if they are accessed. This is the default behavior only the mapping file can be used to specify which classes and fields should behave in this way. Associations When we looked at why the mapping process could not be automated we discussed the following example classes public class Customer int customerid int customerReference String name Email email public class Email String address We also gave the following five questions that it raised Is a unique customer identified by their customer ID or their customer reference Can a given e-mail address be used by more than one customer Should the relationship be represented in the Customer table Should the relationship be represented in the Email table Should the relationship be represented in some third link table The first question can be answered simply it depends on what column you specify as the primary key. The remaining four questions are related and their answers depend upon the object relationships. Furthermore if your Customer class represents the relationship with the EmailAddress using a Collection class or an array it would be possible for a user to have multiple e-mail addresses. CHAPTER 5 AN OVERVIEW OF MAPPING 85 public class Customer int customerId int customerReference String name Set email So you should add another question can a customer have more than one e-mail address The set could contain a single entry so you can t automatically infer that .

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.