Oct 13, 2010

f Comment

How to Do Self Join Many-To-Many Mapping In Hibernate

MenuHow to Do Self Join Many-To-Many Mapping In Hibernate
Hibernate Self Join - Create DB Tables
Hibernate Self Join - Create Java Class
Hibernate Self Join - Create Hibernate Configuration
Hibernate Self Join - Test Java Code
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 ▶
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael