Thursday, June 24, 2010

Manually Assign new value to sequence column

Sometime we need to manully assign a new value to a sequence column. For example, we have a department table with primary key column department_id, which is based on a sequence "department_sequence".

When we try to create a new record in the department table, we will do the following in the

DepartmentVOImpl vo = getDepartmentVOImpl();
Row row = vo.createRow();

SequenceImpl sequence = new SequenceImpl("department_sequence, getDBTransaction());
Number dept_id = sequence.getSequenceNumber();

row.setAttribute("DepartmentId", dept_id);

//set other attribute values...


No comments: