1 Reply Latest reply on Oct 24, 2008 11:09 AM by wolfgangknauf

    many to many mapping exception in EJB3

    mravikrish

      Hello EveryOne,
      i've mapped many2many between user and skill tables ,when it is uni-directional works fine but the problem occurs when i made it to bi-directional. i've written many2many mapping in user class

      The following exception is thrown when i try to insert record.

      Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("SYSTEM"."CUSER_SKILL"."CUSER_USERID")

      CUSER_USERID(column) is getting created automatically in join table.


      thanks in advance.


        • 1. Re: many to many mapping exception in EJB3
          wolfgangknauf

          Hi,

          bi-directional mappings are a bit tricky: you always have to update BOTH sides of the mapping.

          So, if you want to map a Skill to an User, this will NOT work:

          user.getSkills().add ( mySkill);
          entityManager.merge(user);


          You will have to do something like this:
          myUser.getSkills().add ( mySkill);
          mySkill.getUsers().add (myUser);
          entityManager.merge(myUser);


          Hope this helps

          Wolfgang