facebook

Hibernate reverse engineering creates duplicate foreign key!

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

    Hi there!
    My hibernate reverse engineering generates duplicate foreign key mapping.
    Few days ago everything was working fine. I’ve updated my mysql database schema and regenerated the POJOs and mappings.
    Here’s my example generated file:

    Here’s the POJO file:

    
    package com.eon.ibuy.persistence;
    
    import java.sql.Timestamp;
    import java.util.HashSet;
    import java.util.Set;
    
    /**
     * AbstractShop entity provides the base persistence definition of the Shop
     * entity. @author MyEclipse Persistence Tools
     */
    
    public abstract class AbstractShop implements java.io.Serializable {
    
        // Fields
    
        private String shopId;
        private Zone zone;
        private Country country;
        private String shopName;
        private String buildingType;
        private String city;
        private String street;
        private String address;
        private String phone;
        private Timestamp createDate;
        private Set saletransactions = new HashSet(0);
        private Set saletransactions_1 = new HashSet(0);
        private Set loginhistories = new HashSet(0);
        private Set productsupplies = new HashSet(0);
        private Set systemuserShops = new HashSet(0);
        private Set productdistibutionsForShop1Id = new HashSet(0);
        private Set loginhistories_1 = new HashSet(0);
        private Set poses = new HashSet(0);
        private Set productdistibutionsForShop2Id = new HashSet(0);
        private Set shopholderShops = new HashSet(0);
        private Set productdistibutionsForShop2Id_1 = new HashSet(0);
        private Set productsupplies_1 = new HashSet(0);
        private Set poses_1 = new HashSet(0);
        private Set systemuserShops_1 = new HashSet(0);
        private Set productdistibutionsForShop1Id_1 = new HashSet(0);
        private Set shopholderShops_1 = new HashSet(0);
    
        // Constructors
    
        /** default constructor */
        public AbstractShop() {
        }
    
        /** minimal constructor */
        public AbstractShop(String shopId, String shopName, String buildingType) {
            this.shopId = shopId;
            this.shopName = shopName;
            this.buildingType = buildingType;
        }
    
        /** full constructor */
        public AbstractShop(String shopId, Zone zone, Country country,
                String shopName, String buildingType, String city, String street,
                String address, String phone, Timestamp createDate,
                Set saletransactions, Set saletransactions_1, Set loginhistories,
                Set productsupplies, Set systemuserShops,
                Set productdistibutionsForShop1Id, Set loginhistories_1, Set poses,
                Set productdistibutionsForShop2Id, Set shopholderShops,
                Set productdistibutionsForShop2Id_1, Set productsupplies_1,
                Set poses_1, Set systemuserShops_1,
                Set productdistibutionsForShop1Id_1, Set shopholderShops_1) {
            this.shopId = shopId;
            this.zone = zone;
            this.country = country;
            this.shopName = shopName;
            this.buildingType = buildingType;
            this.city = city;
            this.street = street;
            this.address = address;
            this.phone = phone;
            this.createDate = createDate;
            this.saletransactions = saletransactions;
            this.saletransactions_1 = saletransactions_1;
            this.loginhistories = loginhistories;
            this.productsupplies = productsupplies;
            this.systemuserShops = systemuserShops;
            this.productdistibutionsForShop1Id = productdistibutionsForShop1Id;
            this.loginhistories_1 = loginhistories_1;
            this.poses = poses;
            this.productdistibutionsForShop2Id = productdistibutionsForShop2Id;
            this.shopholderShops = shopholderShops;
            this.productdistibutionsForShop2Id_1 = productdistibutionsForShop2Id_1;
            this.productsupplies_1 = productsupplies_1;
            this.poses_1 = poses_1;
            this.systemuserShops_1 = systemuserShops_1;
            this.productdistibutionsForShop1Id_1 = productdistibutionsForShop1Id_1;
            this.shopholderShops_1 = shopholderShops_1;
        }
    
        // Property accessors
    
        public String getShopId() {
            return this.shopId;
        }
    
        public void setShopId(String shopId) {
            this.shopId = shopId;
        }
    
        public Zone getZone() {
            return this.zone;
        }
    
        public void setZone(Zone zone) {
            this.zone = zone;
        }
    
        public Country getCountry() {
            return this.country;
        }
    
        public void setCountry(Country country) {
            this.country = country;
        }
    
        public String getShopName() {
            return this.shopName;
        }
    
        public void setShopName(String shopName) {
            this.shopName = shopName;
        }
    
        public String getBuildingType() {
            return this.buildingType;
        }
    
        public void setBuildingType(String buildingType) {
            this.buildingType = buildingType;
        }
    
        public String getCity() {
            return this.city;
        }
    
        public void setCity(String city) {
            this.city = city;
        }
    
        public String getStreet() {
            return this.street;
        }
    
        public void setStreet(String street) {
            this.street = street;
        }
    
        public String getAddress() {
            return this.address;
        }
    
        public void setAddress(String address) {
            this.address = address;
        }
    
        public String getPhone() {
            return this.phone;
        }
    
        public void setPhone(String phone) {
            this.phone = phone;
        }
    
        public Timestamp getCreateDate() {
            return this.createDate;
        }
    
        public void setCreateDate(Timestamp createDate) {
            this.createDate = createDate;
        }
    
        public Set getSaletransactions() {
            return this.saletransactions;
        }
    
        public void setSaletransactions(Set saletransactions) {
            this.saletransactions = saletransactions;
        }
    
        public Set getSaletransactions_1() {
            return this.saletransactions_1;
        }
    
        public void setSaletransactions_1(Set saletransactions_1) {
            this.saletransactions_1 = saletransactions_1;
        }
    
        public Set getLoginhistories() {
            return this.loginhistories;
        }
    
        public void setLoginhistories(Set loginhistories) {
            this.loginhistories = loginhistories;
        }
    
        public Set getProductsupplies() {
            return this.productsupplies;
        }
    
        public void setProductsupplies(Set productsupplies) {
            this.productsupplies = productsupplies;
        }
    
        public Set getSystemuserShops() {
            return this.systemuserShops;
        }
    
        public void setSystemuserShops(Set systemuserShops) {
            this.systemuserShops = systemuserShops;
        }
    
        public Set getProductdistibutionsForShop1Id() {
            return this.productdistibutionsForShop1Id;
        }
    
        public void setProductdistibutionsForShop1Id(
                Set productdistibutionsForShop1Id) {
            this.productdistibutionsForShop1Id = productdistibutionsForShop1Id;
        }
    
        public Set getLoginhistories_1() {
            return this.loginhistories_1;
        }
    
        public void setLoginhistories_1(Set loginhistories_1) {
            this.loginhistories_1 = loginhistories_1;
        }
    
        public Set getPoses() {
            return this.poses;
        }
    
        public void setPoses(Set poses) {
            this.poses = poses;
        }
    
        public Set getProductdistibutionsForShop2Id() {
            return this.productdistibutionsForShop2Id;
        }
    
        public void setProductdistibutionsForShop2Id(
                Set productdistibutionsForShop2Id) {
            this.productdistibutionsForShop2Id = productdistibutionsForShop2Id;
        }
    
        public Set getShopholderShops() {
            return this.shopholderShops;
        }
    
        public void setShopholderShops(Set shopholderShops) {
            this.shopholderShops = shopholderShops;
        }
    
        public Set getProductdistibutionsForShop2Id_1() {
            return this.productdistibutionsForShop2Id_1;
        }
    
        public void setProductdistibutionsForShop2Id_1(
                Set productdistibutionsForShop2Id_1) {
            this.productdistibutionsForShop2Id_1 = productdistibutionsForShop2Id_1;
        }
    
        public Set getProductsupplies_1() {
            return this.productsupplies_1;
        }
    
        public void setProductsupplies_1(Set productsupplies_1) {
            this.productsupplies_1 = productsupplies_1;
        }
    
        public Set getPoses_1() {
            return this.poses_1;
        }
    
        public void setPoses_1(Set poses_1) {
            this.poses_1 = poses_1;
        }
    
        public Set getSystemuserShops_1() {
            return this.systemuserShops_1;
        }
    
        public void setSystemuserShops_1(Set systemuserShops_1) {
            this.systemuserShops_1 = systemuserShops_1;
        }
    
        public Set getProductdistibutionsForShop1Id_1() {
            return this.productdistibutionsForShop1Id_1;
        }
    
        public void setProductdistibutionsForShop1Id_1(
                Set productdistibutionsForShop1Id_1) {
            this.productdistibutionsForShop1Id_1 = productdistibutionsForShop1Id_1;
        }
    
        public Set getShopholderShops_1() {
            return this.shopholderShops_1;
        }
    
        public void setShopholderShops_1(Set shopholderShops_1) {
            this.shopholderShops_1 = shopholderShops_1;
        }
    
    }
    

    Here’s the mapping file:

    
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse Persistence Tools
    -->
    <hibernate-mapping>
        <class name="com.eon.ibuy.persistence.Shop" table="shop" catalog="ibuy">
            <id name="shopId" type="java.lang.String">
                <column name="shop_id" length="50" />
                <generator class="assigned" />
            </id>
            <many-to-one name="zone" class="com.eon.ibuy.persistence.Zone" fetch="select">
                <column name="zone_id" length="2" />
            </many-to-one>
            <many-to-one name="country" class="com.eon.ibuy.persistence.Country" fetch="select">
                <column name="country_id" length="2" />
            </many-to-one>
            <property name="shopName" type="java.lang.String">
                <column name="shop_name" not-null="true" />
            </property>
            <property name="buildingType" type="java.lang.String">
                <column name="building_type" length="1" not-null="true" />
            </property>
            <property name="city" type="java.lang.String">
                <column name="city" />
            </property>
            <property name="street" type="java.lang.String">
                <column name="street" />
            </property>
            <property name="address" type="java.lang.String">
                <column name="address" />
            </property>
            <property name="phone" type="java.lang.String">
                <column name="phone" />
            </property>
            <property name="createDate" type="java.sql.Timestamp">
                <column name="create_date" length="19" />
            </property>
            <set name="saletransactions" inverse="true">
                <key>
                    <column name="shop_id" length="50" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.Saletransaction" />
            </set>
            <set name="saletransactions_1" inverse="true">
                <key>
                    <column name="shop_id" length="50" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.Saletransaction" />
            </set>
            <set name="loginhistories" inverse="true">
                <key>
                    <column name="shop_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.Loginhistory" />
            </set>
            <set name="productsupplies" inverse="true">
                <key>
                    <column name="shop_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.Productsupply" />
            </set>
            <set name="systemuserShops" inverse="true">
                <key>
                    <column name="shop_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.SystemuserShop" />
            </set>
            <set name="productdistibutionsForShop1Id" inverse="true">
                <key>
                    <column name="shop1_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.Productdistibution" />
            </set>
            <set name="loginhistories_1" inverse="true">
                <key>
                    <column name="shop_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.Loginhistory" />
            </set>
            <set name="poses" inverse="true">
                <key>
                    <column name="shop_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.Pos" />
            </set>
            <set name="productdistibutionsForShop2Id" inverse="true">
                <key>
                    <column name="shop2_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.Productdistibution" />
            </set>
            <set name="shopholderShops" inverse="true">
                <key>
                    <column name="shop_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.ShopholderShop" />
            </set>
            <set name="productdistibutionsForShop2Id_1" inverse="true">
                <key>
                    <column name="shop2_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.Productdistibution" />
            </set>
            <set name="productsupplies_1" inverse="true">
                <key>
                    <column name="shop_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.Productsupply" />
            </set>
            <set name="poses_1" inverse="true">
                <key>
                    <column name="shop_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.Pos" />
            </set>
            <set name="systemuserShops_1" inverse="true">
                <key>
                    <column name="shop_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.SystemuserShop" />
            </set>
            <set name="productdistibutionsForShop1Id_1" inverse="true">
                <key>
                    <column name="shop1_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.Productdistibution" />
            </set>
            <set name="shopholderShops_1" inverse="true">
                <key>
                    <column name="shop_id" length="50" not-null="true" />
                </key>
                <one-to-many class="com.eon.ibuy.persistence.ShopholderShop" />
            </set>
        </class>
    </hibernate-mapping>
    

    Is there any way to synchronize mapping files when database schema changed?

    #296439 Reply

    Loyal Water
    Member

    digz6666,
    Can you switch to a new workspace and check if you are able to reproduce this issue.

    Also, can you go to MyEclipse > Installation Summary > Installation Details and paste the information here for me so that I can ask the dev team to look into this issue.

    #296482 Reply

    Here’s the installation summary:

    
    *** Date: 
    Saturday, March 21, 2009 1:45:14 PM ULAT
    
    ** System properties:
    OS=WindowsVista
    OS version=6.0.0
    Java version=1.5.0_11
    
    
    *** MyEclipse details:
    MyEclipse Enterprise Workbench
    Version: 7.0
    Build id: 7.0-20081201
    
    
    *** Eclipse details:
    MyEclipse Enterprise Workbench
    
    Version: 7.0
    Build id: 7.0-20081201
    
    
    
    
    Eclipse Platform
    
    Version: 3.4.1.r341_v20080731-9I96EiDElYevwz-p1bP5z-NlAaP7vtX6Utotqsu
    Build id: M20080911-1700
    
    
    Eclipse Java Development Tools
    
    Version: 3.4.1.r341_v20080709-0800-7o7tEAfEF_U5qyUgrb2HAp539P97
    Build id: M20080709-0800
    
    
    Eclipse Graphical Editing Framework GEF
    
    Version: 3.4.1.v20080806-67718083A56B4H2A3213573
    Build id: 200809101400
    
    
    Eclipse RCP
    
    Version: 3.4.100.r341_v20080814-989JESIEdAciFYfkZZsBfSwQ2341
    Build id: M20080703-0800
    
    
    Eclipse Plug-in Development Environment
    
    Version: 3.4.1.r341_v20080731-7T7U0E9mlRIuGUYviF_VP
    Build id: M20080703-0800
    
    
    
    
    Eclipse startup command=-os
    win32
    -ws
    win32
    -arch
    x86
    -showsplash
    -launcher
    C:\Users\method\AppData\Local\Genuitec\MyEclipse 7.0\myeclipse.exe
    -name
    Myeclipse
    --launcher.library
    C:\Users\method\AppData\Local\Genuitec\MyEclipse 7.0\../Common\plugins\org.eclipse.equinox.launcher.win32.win32.x86_1.0.101.R34x_v20080731\eclipse_1115.dll
    -startup
    C:\Users\method\AppData\Local\Genuitec\MyEclipse 7.0\../Common\plugins\org.eclipse.equinox.launcher_1.0.101.R34x_v20080819.jar
    -clean
    -configuration
    configuration
    -vm
    C:\Users\method\AppData\Local\Genuitec\Common\binary\com.sun.java.jre.win32.x86_1.5.0.011\bin\client\jvm.dll
    

    Do you need the error log? In the error log there’s many lines that represents java files not found (my pojo files – because I’ve deleted while tomcat has started).

    Also I’ve deleted some jar files from hiberbate 3.2 core library and spring 2.5 library (i forgot exactly what library core or advanced support library).
    I think I’ve deleted following because of compatibility issue (after deletion my web site was working fine, later I have to regenerate mapping files and pojos):

    
    asm.jar
    commons-logging.jar
    commons-logging-1.1.0.jar
    cgi-lib-2.2.3
    
    #296483 Reply

    Sorry for double posting (is there any way to edit my post?).

    I’ve forgot to say that I’ve added commons-logging.1.1.1.jar to hibernate 3.2 core library.
    I think asm.jar is no longer needed because it’s already in spring library with name asm-2.2.3.jar.
    cgi-lib-2.2.3.jar is also in spring library with name cgi-lib-2.2.3-nodep.jar.

    #296518 Reply

    I’ve moved my hibernate.cfg.xml file from src directory to WEBINF directory after the first successful generation. Then I’ve changed my database schema and regenerated.
    Maybe that’s why this is happening. Is there any way to remove hibernate project capability and then add again?

    #296519 Reply

    Sorry for double posting.
    Spring DAO generation is disabled in hibernate reverse engineering.

    #296521 Reply

    I’ve found my some of the problem.
    I’ve created my some config files by hand. And myeclipse don’t recognize that files as spring configuration file.
    So I’ve created new project and all the files by meclipse.

    But the double foreign key mapping generation problem haven’t fixed yet!

    #296538 Reply

    Sorry for my bad.
    That was my fault.
    My table’s foreign keys became double somehow. I didn’t do that. That’s weird.

    Here’s the screenshot:

    The new foreign keys have random name. Do you guys know what makes this happen?

    Finally, sorry for my bad english!

    #299911 Reply

    bhuv
    Member

    Hi,

    I am facing the same problem of duplicate & garbage indexes created in MySQL. Did you find a solution to that problem?

    Thanks

    -B

    #299915 Reply

    1. Delete your database and create fresh new database.

    2. Create spring and hibernate configuration files by myeclipse not by hand.

    or

    Register hand created config files to project.

    <img>http://i43.tinypic.com/2ldceax.jpg</img&gt;
    <img>http://i43.tinypic.com/34s5i6g.jpg</img&gt;
    <img>http://i42.tinypic.com/4lftrc.jpg</img&gt;

    #299916 Reply

    Why disabled editing?



    #299971 Reply

    Loyal Water
    Member

    The dev team is looking into this issue and they will get back to you with a reply asap.

Viewing 12 posts - 1 through 12 (of 12 total)
Reply To: Hibernate reverse engineering creates duplicate foreign key!

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