[hibernate-issues] [Hibernate-JIRA] Commented: (HBX-1120) Incorrect ManyToMany Generation
Darren Salomons (JIRA)
noreply at atlassian.com
Wed Aug 12 00:17:11 EDT 2009
[ http://opensource.atlassian.com/projects/hibernate/browse/HBX-1120?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=33746#action_33746 ]
Darren Salomons commented on HBX-1120:
--------------------------------------
Hi I found your issue when I was also having problems with many-to-many generation. I took a look at your schema and renamed your columns in your join table to user_id and role_id and the generation worked correctly.
I haven't looked into the technical reason why this is the case but I just wanted to let you know.
> Incorrect ManyToMany Generation
> -------------------------------
>
> Key: HBX-1120
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-1120
> Project: Hibernate Tools
> Issue Type: Bug
> Environment: MySQL v5.1
> Hibernate Tools 3.2.4
> Reporter: Henry Chan
> Attachments: hibernateSchemaExport.sql
>
>
> When I run the reverse Engineering Tool to generate my classes, one of these classes does not have the correct manytomany annotation defined correctly:
> In the example below, the I have User, User_Role and Role
> The User classgets generated correctly:
> User.java ...
> @ManyToMany(fetch = FetchType.LAZY)
> @JoinTable(name = "user_role", catalog = "exms", joinColumns = { @JoinColumn(name = "userID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "roleID", nullable = false, updatable = false) })
> public Set<Role> getRoles() {
> return this.roles;
> }
> but Role.java class isn't correct:
> @ManyToMany(fetch = FetchType.LAZY, mappedBy = "roles")
> public Set<User> getUsers() {
> return this.users;
> }
> Where is the @JoinTable in Role.java?
> DROP TABLE IF EXISTS `exms`.`Role` ;
> CREATE TABLE IF NOT EXISTS `exms`.`Role` (
> `roleID` INT NOT NULL AUTO_INCREMENT ,
> `roleName` VARCHAR(45) NOT NULL ,
> PRIMARY KEY (`roleID`) )
> ENGINE = InnoDB;
> -- -----------------------------------------------------
> -- Table `exms`.`Login`
> -- -----------------------------------------------------
> DROP TABLE IF EXISTS `exms`.`Login` ;
> CREATE TABLE IF NOT EXISTS `exms`.`Login` (
> `loginID` INT NOT NULL AUTO_INCREMENT ,
> `userID` INT NULL ,
> `timeStamp` DATETIME NULL ,
> `failedLogins` INT NULL ,
> PRIMARY KEY (`loginID`) ,
> INDEX `fk_Login_User` (`userID` ASC) ,
> CONSTRAINT `fk_Login_User`
> FOREIGN KEY (`userID` )
> REFERENCES `exms`.`User` (`userID` )
> ON DELETE NO ACTION
> ON UPDATE NO ACTION)
> ENGINE = InnoDB;
> -- -----------------------------------------------------
> -- Table `exms`.`User_Role`
> -- -----------------------------------------------------
> DROP TABLE IF EXISTS `exms`.`User_Role` ;
> CREATE TABLE IF NOT EXISTS `exms`.`User_Role` (
> `userID` INT NOT NULL ,
> `roleID` INT NOT NULL ,
> INDEX `fk_User_Role_User` (`userID` ASC) ,
> INDEX `fk_User_Role_Role` (`roleID` ASC) ,
> PRIMARY KEY (`userID`, `roleID`) ,
> CONSTRAINT `fk_User_Role_User`
> FOREIGN KEY (`userID` )
> REFERENCES `exms`.`User` (`userID` )
> ON DELETE NO ACTION
> ON UPDATE NO ACTION,
> CONSTRAINT `fk_User_Role_Role`
> FOREIGN KEY (`roleID` )
> REFERENCES `exms`.`Role` (`roleID` )
> ON DELETE NO ACTION
> ON UPDATE NO ACTION)
> ENGINE = InnoDB;
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list