2 Replies Latest reply on Jan 30, 2002 4:04 PM by dsundstrom

    CMP Bean   ignores the default values

    thomas_x

      hi there !
      i have a simple CMP entityBean for the following table :

      --- (c) by T. Margreiter (DB2 v. 7.1)
      ---------------------------------
      --- Create Table TEST
      ---------------------------------

      create table Test
      (
      LNR varchar(8) NOT NULL with DEFAULT '',
      ANR varchar(14) NOT NULL with DEFAULT '',
      MMG varchar(10) NOT NULL with default 'test'
      constraint test_ixP primary key (lnr)
      )
      --- end SQL script


      when i try to create a Bean (eg: test.create("myTst"))
      i allways get an error from the db2 database, that some fields containing a null value !
      ... but when i set all fields to default values in the ejbcreate methode, it works !



        • 1. Re: CMP Bean   ignores the default values
          lepekhine

          The main idea of CMP beans is to make them separate from the database. You can deploy CMP EJB on any J2EE server backed with any database. So CMP bean can't be "for the following table". CMP bean don't know anything about the table and don't have to know. Rather "the table is for CMP bean". There is no magic. Of course each bean may corresponds to the table row but in unidirectional way.
          The important consequence from it is that you can add additional constraints on the database level in addition to buisiness logic in EJB. For example you may guarantee the referential integriry between tables wich corresponds to the independent J2EE components.

          • 2. Re: CMP Bean   ignores the default values
            dsundstrom

            This is in the EJB spec. All fields are initialized to java defaults on create. If you want defaults, you will have to set them in the ejbCreate method. You could code your system to lookup the defaults in the env context of your bean and then assign them in ejbCreate, but you will have to code it.