I just learn Hibernate in 2 weeks. I self-study by reading book. I'm reading about "mapping collection" and "mapping relationships".
Consider a example. I create a app for book management. One author can write many books. And I will two class Authors and Books. Authors class have authorID, authorName properties. Books class have bookID, bookName properties. In my book which i'm reading, I can apply 3 ways mapping strategy:
-1 Mapping property: Example in my books is add "books" property in Authors class and use Set<Books>book. Then mapping "books" as collection mapping.
-2 Mapping one-to-many: One authors have many books. So, I have one-to-many relationship and I may use <one-to-many> for mapping.
-3 Mapping many-to-one: In this way, i may do the opposite the second way.
My question is, in 3 preceding mapping way, is there any difference for result? Whether have different result if apply other example? I don't know why I ask. But I think writter of Hibernate write have many way, may be have reason.
P/S: Thanks for reading my question. This is my first time joining the forum. I hope I don't have wrong rules for naming my subject. Thanks again and have a nice day everybody!
Mohammed Sardar. wrote:Welcome To Ranch .
Greetings. Many good hearts available here to give their help hands.
It will be really helpful to answer to whom love to help others if the question is more specific and legible to understand. Thanks.
Hello Mohammed! Nice to meet you!
Thanks for your suggestion. I can't edit my first post, so I add the code here.
Example 1: Mapping collection
Example 2: Mapping one-to-many relationship
Example 3: Mapping many-to-one relationship
Jeanne Boyarsky wrote:Options 2 and 3 map the relationship in different directions. Making the similar, but different.
Thank you for the reply, Jeanne!
I know their results are same same. But can you tell me more details? Will that in other case, the results will be different? I mean not with "Author" and "Books".
I don't think accidental Hibernate has two ways for one problem.