001
014
015 package com.liferay.portal.dao.orm.hibernate;
016
017 import com.liferay.portal.kernel.dao.orm.ORMException;
018 import com.liferay.portal.kernel.dao.orm.ObjectNotFoundException;
019 import com.liferay.portal.model.BaseModel;
020
021 import org.hibernate.Session;
022
023
026 public class ExceptionTranslator {
027
028 public static ORMException translate(Exception e) {
029 if (e instanceof org.hibernate.ObjectNotFoundException) {
030 return new ObjectNotFoundException(e);
031 }
032 else {
033 return new ORMException(e);
034 }
035 }
036
037 public static ORMException translate(
038 Exception e, Session session, Object object) {
039
040 if (e instanceof org.hibernate.StaleObjectStateException) {
041 BaseModel<?> baseModel = (BaseModel<?>)object;
042
043 Object currentObject = session.get(
044 object.getClass(), baseModel.getPrimaryKeyObj());
045
046 return new ORMException(
047 object + " is stale in comparison to " + currentObject, e);
048 }
049 else {
050 return new ORMException(e);
051 }
052 }
053
054 }