Amazon I'd like to realize the relationship that a table has a set of parents and a set of children which are all members of that table. How do I do that with Java and Hibernate?
Hibernate has been out there for a long time but I am surprised I couldn't find online a comprehensive tutorial on realizing self join relationships in Hibernate. I am sure many out there are wondering the same thing; so I decided to write a post to address this issue.
First of all here are the exact things I'd like to achieve:
1. Create a Java entity called Keyword. A Keyword has a title and a body.
2. Each Keyword can have a set of keywords as its parents and a set of keywords as its children, and I can easily set and get a keyword's parents and children in Java which when persisted the relationships will be recorded in the database.
Let's first create a database table schema in MySQL! Questions? Let me know!
Create DB Tables ▶