2 Replies Latest reply on Dec 31, 2010 4:40 AM by javatwo

    how to avoid duplicate constraints in mysql table

    javatwo
      Hi, we are using Mysql 5.x and JBoss 5.1.0.

       

      We stop/start JBoss often, and found duplicate constraints, for example,

       

      mysql> show create table Book

       

      CONSTRAINT `FK61687183494D1F9` FOREIGN KEY (`userId`) REFERENCES `user` (`id`),
      CONSTRAINT `FK61687183494DD3C` FOREIGN KEY (`userId`) REFERENCES `user` (`id`),
      CONSTRAINT `FK61687183494E0FD` FOREIGN KEY (`userId`) REFERENCES `user` (`id`),

       

      This will harm mysql performance.

       

      How to prevent Hibernate from generating duplicate constraints? Thanks.
      Dave
        • 1. Re: how to avoid duplicate constraints in mysql table
          wdfink

          Do you know to which table the CONSTRAINT is linked?

          Also how your entity is annotated and how the deployment descriptor looks like?

          - create / remove table by deploy

          - anntotation of relation

          • 2. Re: how to avoid duplicate constraints in mysql table
            javatwo

            public class Merchandise {

             

            @ManyToOne
            @JoinColumn(name="unit")
            public Unit getUnit() {
              return unit;
            }

             

            }

             

            public class Unit {

            ...  

            }

             

            show create table Merchandise

             

            CONSTRAINT `FK859C7BA3FBCB8305` FOREIGN KEY (`unit`) REFERENCES `unit` (`id`),
            CONSTRAINT `FK859C7BA3FBCB8307` FOREIGN KEY (`unit`) REFERENCES `unit` (`id`)

             

            Hibernate: set "hibernate.hbm2ddl.auto" to "update".

             

            How to tell Hibernate not to create such duplicate FOREIGN KEY constraints.  Thanks for help.

            Dave