mirror of
https://gitee.com/jmix/cuba.git
synced 2024-11-30 18:27:56 +08:00
EclipseLink ORM (unfetched attribute exception handler). #PL-5412
This commit is contained in:
parent
c947586c62
commit
f1b0cc18b6
@ -28,13 +28,12 @@ public class OptimisticExceptionHandler extends AbstractGenericExceptionHandler
|
||||
protected Messages messages;
|
||||
|
||||
public OptimisticExceptionHandler() {
|
||||
// todo EL
|
||||
super("org.springframework.orm.jpa.JpaOptimisticLockingFailureException"/*, "org.apache.openjpa.persistence.OptimisticLockException"*/);
|
||||
super("javax.persistence.OptimisticLockException");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doHandle(String className, String message, @Nullable Throwable throwable, WindowManager windowManager) {
|
||||
Pattern pattern = Pattern.compile("\\[([^-]*)-");
|
||||
Pattern pattern = Pattern.compile("Class> (.+)");
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
String entityClassName = "";
|
||||
if (matcher.find()) {
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2015 Haulmont. All rights reserved.
|
||||
* Use is subject to license terms, see http://www.cuba-platform.com/license for details.
|
||||
*/
|
||||
|
||||
package com.haulmont.cuba.gui.exception;
|
||||
|
||||
import com.haulmont.cuba.gui.WindowManager;
|
||||
import com.haulmont.cuba.gui.components.Frame;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
|
||||
import javax.annotation.ManagedBean;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author Konstantin Krivopustov
|
||||
* @version $Id$
|
||||
*/
|
||||
@ManagedBean("cuba_UnfetchedAttributeAccessExceptionHandler")
|
||||
public class UnfetchedAttributeAccessExceptionHandler extends AbstractGenericExceptionHandler {
|
||||
|
||||
private static final Pattern PATTERN = Pattern.compile("at (.+)\\._persistence_get_(.+)\\(");
|
||||
|
||||
public UnfetchedAttributeAccessExceptionHandler() {
|
||||
super("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");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doHandle(String className, String message, @Nullable Throwable throwable, WindowManager windowManager) {
|
||||
String msg = "It usually occurs when the attribute is not included into a view";
|
||||
String defaultMsg = "\n\nSee the log to find out what attribute caused the exception";
|
||||
|
||||
if (throwable != null) {
|
||||
Matcher matcher = PATTERN.matcher(ExceptionUtils.getStackTrace(throwable));
|
||||
if (matcher.find()) {
|
||||
msg += "\n\nEntity: " + matcher.group(1) + "\nAttribute: " + matcher.group(2);
|
||||
} else {
|
||||
msg += defaultMsg;
|
||||
}
|
||||
} else {
|
||||
msg += defaultMsg;
|
||||
}
|
||||
|
||||
windowManager.showNotification("Unfetched attribute access error", msg, Frame.NotificationType.ERROR);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user