java - Hibernate mapping confusion -
the below definition taken hibernate association mapping tutorial here
each book related 1 publisher while 1 publisher may publish many books.
i'd represent above definition below way in java
class book { publisher pub; } class publisher { set<book> books; }
question 1. confused why tutorial says the association book publisher called “many-to-one” association. thought there "one-to-many" association between publisher , book have been right approach.
question 2. below hbm book. why shouldn't declare one-to-many in publisher's hbm mapping. determines location relationship mapping?
<class name="book" table="book"> <many-to-one name="publisher" class="publisher" column="publisher_id" /> </class>
the association book
publisher
many-to-one because there can many books per publisher. irrelevant fact book
aware of own publisher
. association aid hibernate in understanding underlying representation.
there nothing wrong declaring one-to-many relationship publisher
book
. can have both present. depends on data model , how plan on interacting it.
Comments
Post a Comment