You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Danilo Tommasina <dt...@risksys.com> on 2003/07/25 12:20:01 UTC

[ADDITION]: Yet another null / 0 reference problem

I got a look to the rc3 sources and found following:

Storing the Grant instance causes also all its referenced Objects to be stored (why? all auto-xxx are set to false, but this is another problem)
Storing the referenced Role instance will cause the generation of a new Identity, the init(...) method in Identity calls method getKeyValues(...) in BrokerHelper which at some time calls method its getAutoIncrementValue(...) method.
And here is the code that causes my problem:
if ((cv == null) || ((cv instanceof Number) && (((Number) cv).intValue() == 0)))
 since the ID of the Role is 0, in my case cv= BigDecimal( 0 ) (which is not a null reference), then a new ID is generated, however this should not be the case!
why are you also checking if cv.intValue() == 0 ? Is this a compatibility issue with databases other than oracle not supporting null values for numeric fields?
Removing the ' || ((cv instanceof Number) && (((Number) cv).intValue() == 0))' would cause other problems?

thx in advance
bye
danilo

----------

Hi,

(Using Oracle 9i, OJB 1.0rc3 and PB api)
I am experiencing an odd problem while trying to store a new object A that
 references another existing object B with primary key=0. A >> B (one to
 many) Storing the objects can be done without any porblem if the primary key
 of B is not 0.

I have a Object A is of type Grant:

    <class-descriptor class="com.risksys.ors.om.adm.Grant" table="ADM_GRANT"
 >

<!-- COLUMN ADM_GRANT_ID:  -->
        <field-descriptor id="1" name="admGrantId" column="ADM_GRANT_ID"
 jdbc-type="DECIMAL" nullable="false"
             primarykey="true"
             autoincrement="true"
                 sequence-name="ADM_GRANT_SEQ"
                 length="22"
        />

<!-- Foreign Key ADM_ROLE_ID: references table ADM_ROLE -->
        <reference-descriptor
            name="refAdmRoleId"
            class-ref="com.risksys.ors.om.adm.Role"
            auto-retrieve="false"
            auto-update="false"
            auto-delete="false"

            <foreignkey field-ref="admRoleId"/>
        </reference-descriptor>

<!-- ... here come some other references not interesting for the current
 problem --> </class-descriptor>

and the Object B is of type Role:

    <class-descriptor class="com.risksys.ors.om.adm.Role" table="ADM_ROLE" >

<!-- COLUMN ADM_ROLE_ID:  -->
        <field-descriptor id="1" name="admRoleId" column="ADM_ROLE_ID"
 jdbc-type="DECIMAL" nullable="false"
             primarykey="true"
             autoincrement="true"
                 sequence-name="ADM_ROLE_SEQ"
                 length="22"
        />

<!-- Inverse reference to table ADM_GRANT  -->
      <collection-descriptor
         name="refRole_Grant_AdmRoleId"
         element-class-ref="com.risksys.ors.om.adm.Grant"
         auto-retrieve="false"
         auto-update="false"
         auto-delete="false"

         <inverse-foreignkey field-ref="admRoleId"/>
      </collection-descriptor>

<!-- ... here come some other references not interesting for the current
 problem --> </class-descriptor>

----------------------

I am using BigDecimals to wrap the ID references.

Assuming we have a new Grant instance that references an EXISTING Role
 instance with ID= BigDecimal( 0 ) and some other (not interesting) existing
 Objects with valid references, storing the grant will generate following
 sql:

(1) select ADM_GRANT_SEQ.nextval from dual
(2) SELECT
 ADM_GRANT_ID,ADM_ORG_UNIT_ID,ADM_USER_ID,ADM_ROLE_ID,ADM_ORG_UNIT_GROUP_ID
 FROM ADM_GRANT WHERE ADM_GRANT_ID = '1015' (3) select ADM_ROLE_SEQ.nextval
 from dual
(4) INSERT INTO ADM_GRANT
 (ADM_GRANT_ID,ADM_ORG_UNIT_GROUP_ID,ADM_ROLE_ID,ADM_USER_ID,ADM_ORG_UNIT_ID)
 VALUES ('1015','1020','1013','1015','191') (5) rollback

-> rollback with following exception:
org.apache.ojb.broker.KeyConstraintViolatedException: ORA-02291: integrity
 constraint (RCS_ORS_1_0_DEV1.FK_ADM_GRAN_HASROLE_ADM_ROLE) violated - parent
 key not found

statment (3) should not be called (generates the Id '1013'), and the correct
 statement (4) should be: INSERT (...)  VALUES
 ('1015','1020','0','1015','191')

If using a Role with primary key > 0 (for example: 1), then statment (3) is
 not generated and stement (4) is: INSERT (...)  VALUES
 ('1015','1020','1','1015','191')
wich is correct!

I guess that there is still a problem, so that an ID= BigDecimal( 0 ) is
 interpreted as null, however I don't understand why OJB generates statement
 (3) and does not try to insert a null value (which is also wrong)

Any ideas?
thx
bye
danilo


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org