Hibernate version:
3.1
Name and version of the database you are using:
mySQL 5.0 - INNODB
Hey, I need to have a sophisticated many-to-many mapping (or so I think). The problem is kind of hard to explain so I have made a quick muck up of the tables I would use if I were to make it without Hibernate.
Code:
CREATE TABLE `Class` (
`id` int(11) NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `Person` (
`id` int(11) NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `PersonClass` (
`userId` int(11) NOT NULL,
`classId` int(11) NOT NULL,
`status` enum('pending','user','admin') NOT NULL,
`type` enum('student','teacher') NOT NULL,
PRIMARY KEY (`userId`,`classId`),
KEY `classId` (`classId`)
);
So I have a Class which can have a number of Persons associated. A Person is either student or teacher. And a Person is also either pending, user or admin. A Person can be associated with many Classes.
In my "Class" class I would like to have a pending, users (including both users and admins) and a admin Set. I would also like to have a students and teachers Set containing only user or admin Persons.
It is pretty complicated and I could make the mapping via many small many-to-many relations, but then a Person could end up in both the Teacher and Student Set, or worse be both pending and admin. can this kind of mapping be made in Hibernate without having PersonClass as a java class?
By the way comments on my table structure is welcome as long as it does what I have tried to sketch above ...