4 Replies Latest reply on Oct 18, 2008 8:54 AM by Christopher Volk

    sem "generate-entities" and oneToMany manyToOne

    matthieu vidal Newbie

      Hi


      Is sem generate-entities able or not to create oneToMany relationship when encounter a foreign key in a table ??


      I'm using mySQL 5.0 but the only foreign key I've created is ignored and I don't see no link at all beetween the entities created.


      Thanks for your help

        • 1. Re: sem "generate-entities" and oneToMany manyToOne
          Francisco Jose Peredo Noguez Master

          Hi!


          How did you created the foreign key?


          I haven't tried seam-gen and MySql myself, but If you created the foreign key it as explained here
          and you are using the latest MySQL, and the latest JDBC driver it should work...


          If it still doesn't work, maybe you need to set the hibernatetool.metadatadialect to MySqlMetaDataDialect in the hibernate.console configuration.


          Regards,


          • 2. Re: sem "generate-entities" and oneToMany manyToOne
            matthieu vidal Newbie

            Hello


            thanks for your help.


            The only difference I see is that I use Varchar(45) instead of integer.

            • 3. Re: sem "generate-entities" and oneToMany manyToOne
              matthieu vidal Newbie

              It seems that manyToOne relationship cannot be created neither in the entities nor in the forms :o(

              • 4. Re: sem "generate-entities" and oneToMany manyToOne
                Christopher Volk Newbie

                I realize this it's been a while on this thread, but I've spent days banging my head on this, and I've been doing this type of work for a long time.  I hope this helps others avoid such project delays.


                The answer is that MySQL 5 (didn't try prev versions) does not receive multiplicity annotations such as ToOne and ToMany using either seam-gen or hibernate/jboss tools.  I generated my data model from Toad and created DDL for both MySQL 5 and PostgreSQL 8.0.  The annotations for multiplicity are generated for PostgreSQL, but not for MySQL.  I'm not sure where this problem lies - the exporter, the dialect, etc. and don't have time now to check it out.  Luckily for me this project gives me the freedom to choose the db platform and to also control the schema.  I don't envy those stuck with MySQL and hitting this issue.


                I'll note here that this is definitely not the first time I've had to give up on MySQL and switch to PostgreSQL to get an app to work, both my own and third party.


                Of course you can go with the backup plan - generate your entities from MySQL and just add the multiplicity annotations themselves by hand - you still get 90% of your work done by the generator.  Then generate the UI on it's own.  You can make your incremental manual changes to the DB schema via updating the entity classes.  Then just set hibernate.hbm2ddl.auto to 'update' in your persistence.xml or hibernate config to sync the entities and the db schema.


                Good luck...