1 Reply Latest reply on Feb 21, 2006 6:41 PM by epbernard

    Adding entity in a ManyToMany relation

    fred2210

      Hi,

      I have a ManyToMany relation with Entreprise and Tool :
      #Entreprise side

      @ManyToMany(mappedBy="entreprises")
      public Collection<Tool> getTools() {
       return tools;
      }


      # Tool side
      @ManyToMany
      public Collection<Entreprise> getEntreprises() {
       return entreprises;
      }


      The table (Tool_Entreprise) is well created in MySQL.

      But I can't add any tool in the entreprise doing (entreprise and tool being initialized) :
      entreprise.getTools().add( tool );

      No any record is inserted in the table.
      (And no error in jboss/hibernate logs)

      When I Insert a record manually in the table with the right ids, I can see the result doing entreprise.getTools(); (It works).

      How can I add a tool to an entreprise in Java ??

      Thanks,
      Fred.