Sunday, 12 November 2017

Using Groovy Expression or DBSequence to set a Primary Key with a Sequence Number in jdeveloper 12c



Steps:

1. Groovy Expression Method.

Create Sequence in oracle database.
Code :
CREATE SEQUENCE "EMPLOYEE_SEQ"  MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE  ORDER  NOCYCLE ;

I use the EMPLOYEES_SEQ defined in the HR schema to set the PK of the new employee, EMPLOYEE_ID to the next available sequence number.



Now we can open the Employee EO from the model layer. Double click on the Employees EO to open the properties inspector for the EO and select the ‘Attribute’ section.

Now select the EmployeeId in the attributes to get to the attributes properties.

Here we can add a default value as literal, expression or as SQL. We select the ‘Expression’ radio button and click on hte pencel on the right side of the input field.

Here we enter the Groovy expression to get the next sequence number

(new oracle.jbo.server.SequenceImpl("EMPLOYEES_SEQ",adf.object.getDBTransaction())).getSequenceNumber()

After submitting the dialog with OK you should set the ‘Refresh Expression Value’ to ‘true’ and the ‘Updatable’ LOV to ‘While New’.

To avoid this issue,

[Static type checking] - [ADF security error] Calling the constructor for class oracle.jbo.server.SequenceImpl is not permitted.


select Employee_id and then click source tab
  • Go to the source of the entity object xml file
  • Search for the tag "TransientExpression"
  • Check the attribute trustMode. It may have the value "untrusted"
  • Change the value to "trusted". Save and run the app

 <Attribute
    Name="ApplicationId"
    IsNotNull="true"
    Precision="15"
    Scale="0"
    ColumnName="APPLICATION_ID"
    SQLType="NUMERIC"
    Type="java.lang.Long"
    ColumnType="NUMBER"
    TableName="FND_APPLICATION"
    PrimaryKey="true"
    IsUpdateable="while_insert">
    <TransientExpression
      Name="ExpressionScript"
      trustMode="untrusted"
      trustMode="trusted"
      CodeSourceName="FndApplicationRow"/>
    <RecalcCondition
      Name="RecalcExpressionScript"
      trustMode="untrusted"
      CodeSourceName="FndApplicationRow"/>

  </Attribute>
Now the issue should be solved.

Note: The same solution is for the below error. This solution worked for both the issues.

Error: [ADF security error] The method getDBTransaction on class oracle.jbo.server.EntityImpl is not permitted
A word of caution here: JDev 11.1.2.0.0 saves the setting for the refresh condition in the xml file, but the next time you open the dialog again the ‘Refresh Expression Value’ value is gone! I’ll file a bug for this later.

This wraps up the model layer of the app. You can test your work with the Application Module Tester. When you create a new record you’ll see that the EmployeeId is set to the next sequence number.

For more

No comments:

Post a Comment