EclipseLink ORM (fixed unfetched attribute exception handler). #PL-5412

This commit is contained in:
Konstantin Krivopustov 2015-10-01 12:21:23 +00:00
parent b667015e8f
commit 3d581cfac9
2 changed files with 7 additions and 20 deletions

View File

@ -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);
// }
}

View File

@ -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