Is there any way in which i can identify that, if an exception occurs while saving an object through hibernate, then whether the cause of the exception is "Duplicate unique primary key". Something similar to what i do in case of StaleObjectException as follows:
Code:
try {
//save object through Hibernate
}
catch (Exception tapce) {
Throwable te = tapce;
while (te != null) {
if (te.getCause() instanceof StaleObjectStateException) {
logger.error("Some one changed this object");
break;
}
te = te.getCause();
}
}
Thank you.