2 Replies Latest reply on Jul 1, 2004 3:46 PM by Matthias Zint

    Create fails - CMP, CMR & Compound PK

    Matthias Zint Newbie

      Hi there,

      I'm pretty new to this, so maybe someone could help me with this.

      I get the following error message when I try to create a new entry.
      This is just an example database consisting of two tables Moons and Planets.

      The MoonEJB contains the fields planet, moon, radius and diameter and a foreign key relationship to the table Planets.

      When I call the function:

       * @ejb.interface-method view-type = "remote"
       * @jboss-net.web-method
       * @jboss-net.wsdd-operation
       public void addMoon(String pl, String mo, int ra, int di){
       try {
       moHome = getMoonLocalHome();
       } catch (Exception e) {

      I get the following Error Message ->
      Could not create entity
      java.sql.SQLException: Try to insert null into a non-nullable column in statement [INSERT INTO MOONS (PLANET, MOON, RADIUS, DIAMETER, planet) VALUES ('Earth', 'newMoon', 1000, 2000, NULL)]

      I presume the error is due to the fact that I haven't set the relationship between the Moon and the corresponding planet, when I create a new moon.

      The MoonEJB contains the following create method:

       * @return
       * @throws CreateException
       * @ejb.create-method
       public MoonPK ejbCreateMoon(String planet, String moon, int radius, int diameter) throws CreateException{
       return null;
       public void ejbPostCreateMond(String planet, String moon, int radius, int diameter){ }

      The CMP fields are defined like this:
       * @return
       * @ejb.persistent-field
       * @ejb.persistence column-name = "PLANET"
       * @ejb.interface-method view-type = "local"
       public abstract String getPlanet();
       public abstract void setPlanet(String planet);

      and the CMR is defined as follows:
       * @return
       * @ejb.interface-method
       * @ejb.relation name = "PlanetAndMoonRelation"
       * role-name = "PlanetHasMoons"
       * target-role-name = "MoonsHavePlanet"
       * target-ejb = "Planets"
       * @jboss.relation fk-column = "planet"
       * related-pk-field = "planet"
       * fk-constraint = "true"
       public abstract PlanetsLocal getPlanetRel();
       public abstract void setPlanetsRel(PlanetLocal planet);

      Any suggestions ??