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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]