Generating Sequence Number for PrimaryKey in Oracle ADF
It can be done in many ways using programmatic and declarative way. Let us see some of the ways to generate DB Sequence for PK.
Override the Create Method in EmployeesEOImpl class
public void create(AttributeList attributeList) {
super.create(attributeList);
//this is the code
SequenceImpl seq = new SequenceImpl("EMP_SEQUENCE", getDBTransaction());
Number seqNextval = seq.getSequenceNumber();
setEmployeeId(seqNextval); }
Overriding initDefaults() in StudentEOImpl class
protected void initDefaults() {
super.initDefaults();
SequenceImpl seq = new SequenceImpl("STUDENT_BASIC_INFO_SEQ",
getDBTransaction()); populateAttributeAsChanged(STUDENTID,seq.getSequenceNumber().toString());
}
Note: If u didn’t get how to go in to the initDefaults() or Create() methods ,go to source menu in the menu-bar --à override methods & select the above methods
Declarative way
Go to Employee attribute section & double click on EmpId . Edit Attribute dialog will appear, Select value type is expression. In the value Field write the below expression
(new oracle.jbo.server.SequenceImpl("EMP_SEQUENCE",adf.object.getDBTransaction())) .getSequenceNumber()
Declarative way using Trigger
Trigger helps to retain the sequence even after rollback operation is done . Generate a Trigger on your table as below
In the entity attribute section for DeptID , select below properties Type=DBSequence Updatable=Never Refresh After=Update
Read More