TAILIEUCHUNG - Hibernate Tutorial 04

In our online bookshop application, each book is related to one publisher while one publisher may publish many books. | Hibernate Tutorial 04 Many-to-one and One-to-one Association By Gary Mak hibernatetutorials@ September 2006 1. Many-to-one association In our online bookshop application each book is related to one publisher while one publisher may publish many books. The association from book to publisher is called a many-to-one association. As this association is navigable from book to publisher only it is also a kind of unidirectional association. Otherwise if the association is navigable in both directions . from book to publisher and from publisher to book it will be a bi-directional association. Remember that we have a Publisher class in our application that hasn t mapped to the database. Following the best practice of object identifier discussed in last chapter we should add an auto-generated id property on it. public class Publisher private Long id private String code private String name private String address Getters and Setters hibernate-mapping package class name Publisher table PUBLISHER id name id type long column ID generator class native id property name code type string column name CODE length 4 not-null true unique true property property name name type string column name PUBLISHER_NAME length 100 not-null true property property name address type string column name ADDRESS length 200 property class hibernate-mapping Page 1 of 10 For we have added a new persistent object to our application we need to specify it in the Hibernate configuration file also. mapping resource com metaarchit bookshop For our Book class we already have a publisher property which type is Publisher. It is not used in the previous examples. public class Book private Long id private String isbn private String name private Publisher publisher private Date publishDate private Integer price private List chapters Getters and Setters To make use of this property we can add a many-to-one mapping to the mapping definition of Book class. This .

TỪ KHÓA LIÊN QUAN
Đã 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.