gravatar

Populating Primary Key of Entities in 11g

Its a common requirement to populate the primary key of an entity automatically, as soon as an entity is created.

There are many ways to populate the primary key of an entity. There are programmatic ways to populate the primary key. Also there are ways to populate the primary keys based on a database sequence.

In 11g ADFbc can auto populate the primary key of an entity if the java type of the attribute is "java.lang.Long". This is done declaratively. Select the attribute whose value should be populated automatically. Then go to the property inspector. Expand the "Applications" tab and then change the drop down with the label "Application Unique ID" to "true".

That's it..

But for this to work properly, the database that is used for fetching the information should have a table with the name like "S_ROW_ID" and there are many other requirements..If you use the latest 11g database then there is nothing to worry about.

If this does'nt work for you and have to populate the attribute with a value of a DB sequence then do the following .

Select the attribute , whose value has to come from the DB sequence. Go to the property inspector. Expand the "Value" tab and select "Expression" as the "Default value type" radio button. In the "Default Value" input field, provide a groovy expression like "(new oracle.jbo.server.SequenceImpl("DB_Sequence_name",object.getDBTransaction())).getSequenceNumber()"

There are many other ways to populate the primary key. Look into the online documentation for this.