diff --git a/modules/global/src/com/haulmont/cuba/core/sys/persistence/CubaEntityFetchGroup.java b/modules/global/src/com/haulmont/cuba/core/sys/persistence/CubaEntityFetchGroup.java index d36612a941..211554d131 100644 --- a/modules/global/src/com/haulmont/cuba/core/sys/persistence/CubaEntityFetchGroup.java +++ b/modules/global/src/com/haulmont/cuba/core/sys/persistence/CubaEntityFetchGroup.java @@ -23,25 +23,9 @@ public class CubaEntityFetchGroup extends EntityFetchGroup { @Override public String onUnfetchedAttribute(FetchGroupTracker entity, String attributeName) { - if (entity._persistence_getSession() == null) { - throw new IllegalEntityStateException(ExceptionLocalization.buildMessage("cannot_get_unfetched_attribute", new Object[]{entity, attributeName})); - } - if (attributeName == null) { // occurs on merge + if (attributeName == null && entity._persistence_getSession() != null) { // occurs on merge return super.onUnfetchedAttribute(entity, null); } - throw new IllegalEntityStateException("Attribute '" + entity.getClass().getSimpleName() + "." + attributeName + - "' is not included into view"); + throw new IllegalEntityStateException(ExceptionLocalization.buildMessage("cannot_get_unfetched_attribute", new Object[]{entity, attributeName})); } - -// @Override -// public String onUnfetchedAttributeForSet(FetchGroupTracker entity, String attributeName) { -// if (entity instanceof ChangeTracker) { -// AttributeChangeListener changeListener = -// (AttributeChangeListener) ((ChangeTracker) entity)._persistence_getPropertyChangeListener(); -// if (changeListener != null && changeListener.hasChanges()) -// throw new IllegalStateException("Attribute '" + entity.getClass().getSimpleName() + "." + attributeName + -// "' is unfetched. Unable to refresh the instance because its state has already been changed"); -// } -// return super.onUnfetchedAttributeForSet(entity, attributeName); -// } } \ No newline at end of file diff --git a/modules/gui/src/com/haulmont/cuba/gui/exception/UnfetchedAttributeAccessExceptionHandler.java b/modules/gui/src/com/haulmont/cuba/gui/exception/UnfetchedAttributeAccessExceptionHandler.java index 66bd2c7232..ffcdb05c2f 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/exception/UnfetchedAttributeAccessExceptionHandler.java +++ b/modules/gui/src/com/haulmont/cuba/gui/exception/UnfetchedAttributeAccessExceptionHandler.java @@ -24,12 +24,15 @@ public class UnfetchedAttributeAccessExceptionHandler extends AbstractGenericExc private static final Pattern PATTERN = Pattern.compile("at (.+)\\._persistence_get_(.+)\\("); public UnfetchedAttributeAccessExceptionHandler() { - super("org.eclipse.persistence.exceptions.ValidationException"); + super("com.haulmont.cuba.core.global.IllegalEntityStateException", + "org.eclipse.persistence.exceptions.ValidationException"); } @Override protected boolean canHandle(String className, String message, @Nullable Throwable throwable) { - return message.contains("An attempt was made to traverse a relationship using indirection that had a null Session"); + return className.equals("com.haulmont.cuba.core.global.IllegalEntityStateException") + || (className.equals("org.eclipse.persistence.exceptions.ValidationException") + && message.contains("An attempt was made to traverse a relationship using indirection that had a null Session")); } @Override