Tuesday, April 14, 2009

Workaround for LOV on Primary Key Attribute in Create Mode

In February, I was blogging about - Workaround for LOV on Primary Key Attribute. Provided workaround and sample application was working nicely, but it was working only in edit mode, when already existing row was updated. There was a need in my project, to update previously developed workaround in order to have working functionality when current row is in create mode.

I'm posting updated sample application, you can download it - LOVPrimaryKeyCreate.zip. This sample implements workaround for LOV on Primary Key for both cases - edit and create modes. Most probably you will face described problem in current JDeveloper/ADF builds (5188 and 5205).

One specific with create mode is that Primary Key usually have database constraint - Mandatory:

This means, on runtime - when user will try to create new row and will do commit - validation error will be generated for LOV attribute. Its because value from dummy attribute will not be copied into real attribute, validation will fire first for empty real attribute value:

Its possible to solve this problem, by simply updating previously described workaround. Idea is to initialize real key attribute with some dummy value when create is invoked. In my sample, I'm using main key negative value retrieved from DBSequence. I'm assigning this value in overriden create method:

This means, validation will not be fired anymore and dummy value will be changed with a real one in doDML() method (same as in original version of workaround):

With described update, workaround works well for newly created row:

Spanish Summary:

Este post es una actualizaciĆ³n de un post anterior en el que Andrejus muestra como evitar un bug que se produce cuando queremos trabajar con una Lista de Valores (LOV) sobre un campo de una tabla. El post anterior solo consideraba el uso de LOV cuando la tabla estaba en modo de consulta, sin embargo esta actualizaciĆ³n considera las tablas en modo creacion y lectura.


Carles Biosca said...

I think the solution is easiest: just uncheck the mandatory attribute for the database attribute and check it for your transient.

If the user doesn't inform the field, the framework will display the validation for transient attribute. The existing database constraint will not be thrown since you always inform the database field before doDML.

(at least, in JDeveloper 10g3 it would work)

Andrej Baranovskij said...


Its a bad practice to remove Database Constraints on Entity object attributes. What if second developer will try to use in his form original attribute.


Barbara Gelabert said...

Hi, do you know whether bug #8275169 is fixed in JDeveloper

Ramesh said...

Hi, the download url is not working. Can you please provide with the updated url.


Andrej Baranovskij said...

Check this post: http://andrejusb.blogspot.lt/2017/08/my-blog-samples-download-repository-for.html