9 Replies Latest reply on Jan 17, 2013 11:31 PM by anika001

    Many-to-Many on the GUI

    bputersznit

      Hello.

      Was trying my hand at creating the Hurricane - Continents M2M relationship example. Added 'name' string fields to each. I can add M2M but cant seem to see them. Is there something in the scaffold or build process my noob mind has missed? Obliged in advance for any assistance.

       

      I am was using the intial Customer tute to build upon.

       

      some cli shots for info:

       

      [alive] model $ ls

      Continent.java     Customer.java      Hurricane.java

       

      [alive] Continent.java $ ls

       

       

      [fields]

      private::Long::id;               private::Set::hurricanes;        private::String::name;           private::int::version;

       

       

      [methods]

      public::equals(Object that)::boolean                                              public::getHurricanes()::Set

      public::getId()::Long                                                             public::getName()::String

      public::getVersion()::int                                                         public::hashCode()::int

      public::setHurricanes(final Set<Hurricane> hurricanes)::void                      public::setId(final Long id)::void

      public::setName(final String name)::void                                          public::setVersion(final int version)::void

      public::toString()::String                                                       

       

       

       

      [alive] Hurricane.java $ ls

       

       

      [fields]

      private::Long::id;               private::Set::continents;        private::String::name;           private::int::version;

       

       

      [methods]

      public::equals(Object that)::boolean                                              public::getContinents()::Set

      public::getId()::Long                                                             public::getName()::String

      public::getVersion()::int                                                         public::hashCode()::int

      public::setContinents(final Set<Continent> continents)::void                      public::setId(final Long id)::void

      public::setName(final String name)::void                                          public::setVersion(final int version)::void

      public::toString()::String 

        • 1. Re: Many-to-Many on the GUI
          lincolnthree

          Am I correct in assuming that you cannot see the relationship generated in the UI, but that it is properly generated in the source code?

           

          If this is the case, try leaving the project (cd ~; cd -), and returing to it. Then re-generate the UI. There is a bug that causes (for some reason) the state of the code to be cached and must be re-parsed to properly generate new relationships after it has already been generated once.

           

          Let me know if this helps, thanks!

           

          ~Lincoln

          • 2. Re: Many-to-Many on the GUI
            bputersznit

            Thanks for getting back to me Lincoln.

            I did as you suggested. What seems to be happening is that I can edit and add Huricanes to contentents. They show up while editing. i save the Continent. I then go back to edit the same Continent, and the Huricanes are gone. The m2m relationship doesn't seem to persist. The steps I performed to get this result were:

            1. start forge;
            2. navigate to the alive/../models;
            3. to go into both Continent & Huricane and 'scaffold from-entity' in each;
            4. then 'build';
            5. then 'forge install-plugin jboss-as-7';
            6. then 'as7 setup';
            7. then 'as7 deploy';
            8. then browsered to localhost:8080/alive
            9. performed the app actions above.

            Do let me know what I am doing wrong.

            Regards,

            Bernard.

            • 3. Re: Many-to-Many on the GUI
              bputersznit

              Belay the last - don't know why, but now it SEEMS to be working now. Wondering if I was clueless on the GUI logic. Will confirm by making all sorts of m2m relations and deleting some.

              • 4. Re: Many-to-Many on the GUI
                bputersznit

                Take it back. It is REALLY weird:
                I can nominally assign Hurricanes to Continents or Continents to Hurricanes, and they show up while editing. Then I save. HOWEVER, only the saved Huricane with one or more Continents persist. The OPPOSITE, saved Continent with one or more Hurricane DO NOT! Could this be a Hibernate Issue?

                • 5. Re: Many-to-Many on the GUI
                  lincolnthree

                  Hmmm, this is very strange indeed. It could be a hibernate qwerk where only one side of the relationship is able to save the entities. Or perhaps forge is doing something wrong and not actually doing the save correclty by adding entities to the owning side of the relationship? Not sure...

                  • 6. Re: Many-to-Many on the GUI
                    bputersznit

                    Various 'ls' from the model:

                     

                     

                    alive] model $ ls

                    Continent.java     Customer.java      Hurricane.java    

                    [alive] model $ cd Continent.java

                    [alive] Continent.java $ ls

                     

                     

                    [fields]

                    private::Long::id;               private::Set::hurricanes;        private::String::name;           private::int::version;

                     

                     

                    [methods]

                    public::equals(Object that)::boolean                                              public::getHurricanes()::Set

                    public::getId()::Long                                                             public::getName()::String

                    public::getVersion()::int                                                         public::hashCode()::int

                    public::setHurricanes(final Set<Hurricane> hurricanes)::void                      public::setId(final Long id)::void

                    public::setName(final String name)::void                                          public::setVersion(final int version)::void

                    public::toString()::String                                                       

                     

                     

                    [alive] Continent.java $ cd ../Hurricane.java

                    [alive] Hurricane.java $ ls

                     

                     

                    [fields]

                    private::Long::id;               private::Set::continents;        private::String::name;           private::int::version;

                     

                     

                    [methods]

                    public::equals(Object that)::boolean                                              public::getContinents()::Set

                    public::getId()::Long                                                             public::getName()::String

                    public::getVersion()::int                                                         public::hashCode()::int

                    public::setContinents(final Set<Continent> continents)::void                      public::setId(final Long id)::void

                    public::setName(final String name)::void                                          public::setVersion(final int version)::void

                    public::toString()::String                                                       

                     

                     

                    [alive] Hurricane.java $

                    • 7. Re: Many-to-Many on the GUI
                      bputersznit

                      Could it be modeled explitly with a ContinentHurricane intersection table and have the scaffold command figure it out?

                      • 8. Re: Many-to-Many on the GUI
                        lincolnthree

                        I think the scaffold should still work if you use a @JoinTable. It's worth a try.

                        • 9. Re: Many-to-Many on the GUI
                          anika001

                          Am I correct in assuming that you cannot see the relationship generated in the UI, but that it is properly generated in the source code?

                           

                          If this is the case, try leaving the project (cd ~; cd -), and returing to it. Then re-generate the UI. There is a bug that causes (for some reason) the state of the code to be cached and must be re-parsed to properly generate new relationships after it has already been generated once.

                           

                          Let me know if this helps, thanks!

                          1 of 1 people found this helpful