Discussions

EJB programming & troubleshooting: Problem with ejbCreate method : JBoss / CMR / CMP

  1. Hi there,

    I want to insert a row into a database. The table I want to insert data into consists of a compound primary key, CMP-fields and one CMR field.

    I wrote a corresponding ejbCreate method that addresses all the CMP-fields, but I don't know if I have to set the CMR field as well and where ...

    The error I got is as follows:

    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)]

    PLANET and MOON = Primary Key and CMP fields
    RADIUS and DIAMETER = additional CMP fields
    planet = CMR field


    The create method is as follows:

    /**
    * @return
    * @throws CreateException
    *
    * @ejb.create-method
    */
    public MoonPK ejbCreateMoon(String planet, String moon, int radius, int diameter) throws CreateException{
    setPlanet(planet);
    setMoon(moon);
    setRadius(radius);
    setDiameter(diameter);
    return null;
    }

    public void ejbPostCreateMond(String planet, String moon, int radius, int diameter){ }

    Maybe someone can help me with that.

    Thank you very much
    matt
  2. Hi M.Z.

    I think that you are doing a litle mistake, because in ejbCreate you set only CMP-Fields, so after the bean is create and inserted new row in data base, with the ejbPostCreate you set CMR-field.
    All fields that is CMR must to have a respective colunm nullable in table data base.
    All field of a compound primary key must be a sub-set of CMP fields.

    You want to insert a row into a database. The table I want to insert data into consists of a compound primary key, CMP-fields and one CMR field.
    This is impossible, because compound primary key only are permited for CMP-fields. Read the Spec.

    Good Look

    Daniel Shimura Goldszmit
    SCJP
    SCBCD