Monday, March 10, 2014

ADF: DBSequence attribute got an empty value for a new row

From the section "4.10.10 How to Get Trigger-Assigned Primary Key Values from a Database Sequence" in the documentation "Developing Fusion Web Applications with Oracle Application Development Framework" at:

http://docs.oracle.com/middleware/1212/adf/ADFFD/bcentities.htm#ADFFD19777

We have the following description:
"When you create a new entity row whose primary key is a DBSequence, a unique negative number is assigned as its temporary value. This value acts as the primary key for the duration of the transaction in which it is created. "
But sometimes, for some reason, you could come across the problem that a DBSequence attribute remains empty for a new row. In my case, it happened to an entity newly created after I manually switched Data Type Map of the model project from Java Extended for Oracle to Java.

To fix this problem, you need make sure DefaultValue and Domain properties of the attribute are there as the following highlighted lines:

<Attribute
    Name="ContentItemId"
    Precision="19"
    ColumnName="CNT_ITEM_ID"
    SQLType="NUMERIC"
    Type="oracle.jbo.domain.DBSequence"
    ColumnType="NUMBER"
    TableName="FMM_CNT_ITEM"
    PrimaryKey="true"
    IsUpdateable="while_insert"
    DefaultValue="@0"
    Domain="oracle.jbo.domain.DBSequence"
    RetrievedOnInsert="true">

The domain object and the magic default value "@0" cause the view object to generate a negative number as the temporary key.

You can also find a discussion on this issue at:

https://java.net/projects/adfemg/lists/issues/archive/2013-05/message/64

No comments:

Post a Comment