- TooManyObjectException terjadi ketika Entity Object Row mempunyai duplikat primary key (PK)
- DMLException terjadi ketika execute sql ke database
- Pertama - tama saya membuat project ADF Application, dimana ADF-Model menggunakan user hr (sampel oracle database).
- Klik Enity Object Employees dan generate EmployeesImpl seperti gambar dibawah.
- Buka EmployeesImpl.java, modfikasi method doDML dan setEmployeeId seperti dibawah :
/**
* Custom DML update/insert/delete logic here.
* @param operation the operation type
* @param e the transaction event
*/
protected void doDML(int operation, TransactionEvent e) {
try {
super.doDML(operation, e);
} catch (DMLException ex) {
ex.printStackTrace();
throw new JboException("Error : Gagal menambahkan data dengan employee ID : " +
ex.getEntityRow().getAttribute(0));
}
}
/**
* Sets <code>value</code> as the attribute value for EmployeeId.
* @param value value to set the EmployeeId
*/
public void setEmployeeId(Number value) {
try{
setAttributeInternal(EMPLOYEEID, value);
}catch(TooManyObjectsException ex){
ex.printStackTrace();
throw new JboException("Duplicate data employee id tidak diijinkan");
}
}
- Lalu saya mencoba commit data dan muncul pesan error yang sudah di modifikasi
- Dan kali ini kita mencoba memasukkan data employeeID yang sudah ada di database
Sekian blog saya kali ini :)
https://blogs.oracle.com/jdevotnharvest/entry/displaying_exceptions_thrown_or_catched
http://andrejusb.blogspot.com/2010/05/differences-of-handling-jboexception-in.html
http://docs.oracle.com/cd/E12839_01/apirefs.1111/e10653/oracle/jbo/JboException.html





No comments:
Post a Comment