mysqlhibernatehibernate-tools

Hibernate Tools not recognizing many to many relation


When I try to auto-generate my entity classes, hibernate tools generates the many to many class and doesn't make the generation many to many. These are my tables:

CREATE TABLE `role`(
    `id` int(13) not null auto_increment,
    name varchar(255),
    primary key(id)
);

CREATE TABLE `user`(
    `id` int(13) not null auto_increment,
    `username` varchar(255),
    `password` CHAR(60) CHARACTER SET latin1 COLLATE latin1_bin,
    `passwordconfirm` BIT(1) DEFAULT b'0',
    primary key(id)
);


CREATE TABLE `role_user`(
    `role_id` int(13) not null,
    `user_id` int(13) not null,
    CONSTRAINT `FK_User_Role` FOREIGN KEY (`role_id`) REFERENCES `role`(`id`),
    CONSTRAINT `FK_Role_User` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`)
);

And these are my clases:

enter image description here

And in the classes, they have their relations mapped one to many. I have set the "auto detect many to many relations" option active, so, I don't know what's the problem with this.

Any help? Thanks in advance!


Solution

  • Ok, after hours and hours trying and don't get the solution, I post this and five minutes after I find the solution: I added in the table "role_user" the sentence PRIMARY KEY (role_id, user_id), so, it's working! I leave this for someone that has the same problem.