facebook

many-to-many mapping reverse engineering not working?

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 15 posts - 1 through 15 (of 27 total)
  • Author
    Posts
  • #302341 Reply

    Dr.Drane
    Member

    Hello,

    When I try to reverse engineer a simple database with a many-to-many relationship, like this:

    I also get a class for the User_has_language table. Is this normal?

    Because having a User with a collection of Language and vice versa seems to logical OO variant of this database. Why would I need a User_has_language object?

    I hope my question is a bit clearly formulated.

    Thanks a lot in advance and have a nice day!

    Jochen

    #302374 Reply

    Jochen,
    You can check the “Enable many-to-many detection” option to avoid user_has_language objects.
    You will have to remove the previously generated code and RE again.
    Let me know if that helps.

    #302609 Reply

    Dr.Drane
    Member

    Hi Shaline,

    That din’t help unfortunately. I still get the XXXhasYYY objects.
    If you want I can post or mail the .sql file so you can see for yourself that it doesn’t seem to work.

    Thanks a lot in advance!

    Kind regards,

    Jochen

    #302610 Reply

    Dr.Drane
    Member

    To give you some more info:

    I create a new web project. Add Spring 2.5 functionality. Add JPA (via Hibernate) functionality.
    Then I generate entities & DAO’s from the database using Spring DAO’s and I make sure that the “Enable many-to-many detection” is marked.

    This is the database:

    — phpMyAdmin SQL Dump
    — version 3.1.3.1
    http://www.phpmyadmin.net

    — Host: localhost
    — Generation Time: Sep 22, 2009 at 03:42 PM
    — Server version: 5.1.33
    — PHP Version: 5.2.9

    SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;


    — Database: `testdb`

    — ——————————————————–


    — Table structure for table `language`

    CREATE TABLE IF NOT EXISTS `language` (
    `idlanguage` int(11) NOT NULL,
    `name` varchar(45) DEFAULT NULL,
    PRIMARY KEY (`idlanguage`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;


    — Dumping data for table `language`

    — ——————————————————–


    — Table structure for table `user`

    CREATE TABLE IF NOT EXISTS `user` (
    `idUser` int(11) NOT NULL,
    `name` varchar(45) DEFAULT NULL,
    `password` varchar(45) DEFAULT NULL,
    PRIMARY KEY (`idUser`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;


    — Dumping data for table `user`

    — ——————————————————–


    — Table structure for table `user_has_language`

    CREATE TABLE IF NOT EXISTS `user_has_language` (
    `User_idUser` int(11) NOT NULL,
    `language_idlanguage` int(11) NOT NULL,
    PRIMARY KEY (`User_idUser`,`language_idlanguage`),
    KEY `fk_User_has_language_User` (`User_idUser`),
    KEY `fk_User_has_language_language` (`language_idlanguage`)
    ) Engine=InnoDB DEFAULT CHARSET=latin1;


    — Dumping data for table `user_has_language`

    #302625 Reply

    Jochen,
    I could not replicate this at my end. I created a new web project, added spring 2.5 capabilities, added JPA capabiliites (selected Hibernate when adding JPA). When I selected “Generate Entities and DAO’s” from the context menu of the project and checked the option “Enable many-to-many detection”, XXXhasYYY objects are not generated.
    I have attached a screen shot for your reference.

    Attachments:
    You must be logged in to view attached files.
    #302630 Reply

    Dr.Drane
    Member

    That is very odd…I get a different result:

    What version of mysql DB / mysql driver jar / MyEclipse are you using?
    You leave all the settings (including the annotions settings) just to default?

    Thanks again for all the help!

    Kind regards,

    Jochen

    #302631 Reply

    Jochen,
    This is really strange. I have the same settings here. I tested with MySql 5, ME7.5 and mysql-connector-java-3.1.14-bin.jar.
    One quick question. Did you delete all your previously generated classes before generating entities and DAO’s again?
    From the above screen shot, I notice that you can safely remove the package be.tradelec.model.
    Can you remove the package and do the generation again?
    Let me know if you still have the issue.

    #302655 Reply

    Dr.Drane
    Member

    @support-shalini wrote:

    Jochen,
    This is really strange. I have the same settings here. I tested with MySql 5, ME7.5 and mysql-connector-java-3.1.14-bin.jar.
    One quick question. Did you delete all your previously generated classes before generating entities and DAO’s again?
    From the above screen shot, I notice that you can safely remove the package be.tradelec.model.
    Can you remove the package and do the generation again?
    Let me know if you still have the issue.

    I even created a new a project every time so there was no need to delete the previous sources. (checking the include files box when deleting of course)

    I’m using the latest download of MyEclipse 7.5 and MySQL client version: 5.0.51a

    The mysql connector jar seems to be another version though:
    mysql-connector-java-5.1.7-bin

    Can’t seem to download your version of the connector but I can retry with the 5.1.10 version which now seems to be the latest.

    Tomorrow I will take my personal laptop to work and will try again with my laptop…

    Thanks already for all the help, will keep you informed here.

    Kind regards,

    Jochen

    #302656 Reply

    Dr.Drane
    Member

    Are you perhaps using XAMPP for the mysql database or a stand alone version?

    #302657 Reply

    Dr.Drane
    Member

    And did you use the database script I pasted here or did you recreate it yourself?

    #302660 Reply

    Dr.Drane
    Member

    Just did a retry with latest version of XAMPP + latest version of the connector jar.

    Also I now used a version of eclipse with MyEclipse 7.5 plugged in, instead of a standalone MyEclipse.

    But still same problem.

    Do you also have a MyISAM database with a MyISAM “user_has_language” table, and the “language” and “user” tables in InnoDB?

    Thanks and greets

    #302749 Reply

    Jochen,
    I will escalate this issue to the dev team.
    May be they can help you out.

    #303000 Reply

    Dr.Drane
    Member

    Thank you Shalini!

    I’ve sent you a private message here too.
    Did you perhaps already have the time to read it?

    Kind regards,

    Jochen

    #303024 Reply

    Loyal Water
    Member

    Jochen,
    Im afraid the persistence team is still looking into this and they haven’t got back to me with a reply yet. We will try and update you soon.

    #303163 Reply

    Hi Support Team/Jochen,

    Did you find a resolution to this problem? I am running into the same issue and would appreciate quick help. I am using MySQL 5, MyEclipse 7.5, Hibernate 3.2.6 GA through JPA and Java 6.

    Here’s my problem (the sql is attached at the end for reference):

    I have two entities, ROLE and GROUP. They have a many-to-many relationship. i.e. a GROUP consists of many ROLE’s and a ROLE can be a part of many GROUP’s. I created tables for ROLE and GROUP, and another one for ROLE_GROUP_MAPPING. The PK for the ROLE_GROUP_MAPPING is the combination of ROLE_ID and GROUP_ID.

    When I reverse engineer the code, I get a class for RoleGroupMapping. Generated code for Role and Group classes each has a Set of RoleGroupMapping object. This is not what I expect to happen. The right way to handle this situation would be for Role to have a Set of Groups and vise-versa.

    When can I see this fixed?

    Second, related, question: I suspect one can control the generated class structure through jpa.reveng.xml. But where is the specification of the format for this file? I would like to know all options I can specify in that file. So is there a DTD or schema for this file that I can refer to?

    Thanks,
    Unmesh

    SQL:

    create table groupinfo (
      group_id                                integer not null auto_increment,
      group_name                            varchar(20) unique not null,
      remarks                                varchar(80),
      creation_date                           timestamp(8)                 not null default '2009-10-10 00:00:00',
      primary key (group_id)
    ) TYPE=InnoDB;
    
    create table roleinfo (
      role_id                                integer not null auto_increment,
      role_name                                varchar(20) unique not null,
      remarks                                varchar(80),
      creation_date                           timestamp(8)                 not null default '2009-10-10 00:00:00',
      primary key (role_id)
    ) TYPE=InnoDB;
    
    -- Many-to-many mapping of Roles and Groups
    create table role_group_mapping (
      role_id                                 integer,
      group_id                                integer,
      creation_date                           timestamp(8)                 not null default '2009-10-04 00:00:00',
      primary key (role_id, group_id),
      foreign key (group_id)                 references groupinfo(group_id),
      foreign key (role_id)                 references roleinfo(role_id)
    ) TYPE=InnoDB;
Viewing 15 posts - 1 through 15 (of 27 total)
Reply To: many-to-many mapping reverse engineering not working?

You must be logged in to post in the forum log in