扩展实体及界面后“编辑”按钮报错

我通过实体及界面扩展,在访问组增加了“phone”字段:


但增加字段之后“编辑”按钮报错

其日志如下:

IllegalStateException: Cannot get unfetched attribute [phone] from detached object com.company.myapp.entity.ExtGroup-0fa2b1a5-1d68-4d69-9fbd-dff348347f93 [detached].

java.lang.IllegalStateException: Cannot get unfetched attribute [phone] from detached object com.company.myapp.entity.ExtGroup-0fa2b1a5-1d68-4d69-9fbd-dff348347f93 [detached].
at org.eclipse.persistence.internal.queries.EntityFetchGroup.onUnfetchedAttribute(EntityFetchGroup.java:100)
at com.haulmont.cuba.core.sys.persistence.CubaEntityFetchGroup.onUnfetchedAttribute(CubaEntityFetchGroup.java:74)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.processUnfetchedAttribute(EntityManagerImpl.java:2998)
at com.haulmont.chile.core.model.impl.AbstractInstance._persistence_checkFetched(AbstractInstance.java)
at com.company.myapp.entity.ExtGroup._persistence_get_phone(ExtGroup.java)
at com.company.myapp.entity.ExtGroup.getPhone(ExtGroup.java:19)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at com.haulmont.chile.core.model.utils.MethodsCache.invokeGetter(MethodsCache.java:71)
at com.haulmont.chile.core.model.impl.AbstractInstance.getValue(AbstractInstance.java:96)
at com.haulmont.cuba.core.entity.BaseGenericIdEntity.getValue(BaseGenericIdEntity.java:146)
at com.haulmont.chile.core.model.utils.InstanceUtils.getValueEx(InstanceUtils.java:129)
at com.haulmont.chile.core.model.impl.AbstractInstance.getValueEx(AbstractInstance.java:139)
at com.haulmont.cuba.gui.components.data.value.DatasourceValueSource.getValue(DatasourceValueSource.java:124)
at com.haulmont.cuba.gui.components.data.value.ValueBinder$ValueBindingImpl.valueSourceStateChanged(ValueBinder.java:262)
at com.haulmont.bali.events.EventHub.publish(EventHub.java:170)
at com.haulmont.cuba.gui.components.data.value.DatasourceValueSource.setState(DatasourceValueSource.java:92)
at com.haulmont.cuba.gui.components.data.value.DatasourceValueSource.datasourceStateChanged(DatasourceValueSource.java:197)
at com.haulmont.bali.events.EventRouter.fireEvent(EventRouter.java:45)
at com.haulmont.cuba.gui.data.impl.AbstractDatasource.fireStateChanged(AbstractDatasource.java:267)
at com.haulmont.cuba.gui.data.impl.DatasourceImpl.setItem(DatasourceImpl.java:189)
at com.haulmont.cuba.gui.components.AbstractEditor.setItemInternal(AbstractEditor.java:226)
at com.haulmont.cuba.gui.components.AbstractEditor.setItem(AbstractEditor.java:146)
at com.haulmont.cuba.gui.components.AbstractEditor.setEntityToEdit(AbstractEditor.java:437)
at com.haulmont.cuba.web.sys.WebScreens.openEditor(WebScreens.java:1200)
at com.haulmont.cuba.gui.components.HasWindowManager.openEditor(HasWindowManager.java:132)
at com.haulmont.cuba.gui.components.actions.EditAction.internalOpenEditor(EditAction.java:287)
at com.haulmont.cuba.gui.components.actions.EditAction.actionPerform(EditAction.java:231)
at com.haulmont.cuba.web.gui.components.WebButton.buttonClicked(WebButton.java:62)
at com.haulmont.cuba.web.widgets.CubaButton.fireClick(CubaButton.java:76)
at com.vaadin.ui.Button$1.click(Button.java:57)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:153)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:115)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:431)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:396)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:260)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:82)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1577)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:425)
at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:329)
at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:215)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:107)
at org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:73)
at com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:835)

请问一下,该问题出现的原因是什么?怎么解决呢?

贴一下你的扩展实体代码

group-edit.xml的扩展:


group实体扩展代码:

package com.company.myapp.entity;

import com.haulmont.cuba.core.entity.annotation.Extends;
import com.haulmont.cuba.security.entity.Group;

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity(name = “myapp_ExtGroup”)
@Extends(Group.class)

public class ExtGroup extends Group {
private static final long serialVersionUID = -5132225515497143586L;

@Column(name = "PHONE")
protected String phone;

public String getPhone() {
    return phone;
}

public void setPhone(String phone) {
    this.phone = phone;
}

}

确认一下这步做了没有:
https://doc.cuba-platform.cn/manual-7.0-chs/entity_extension.html

Group-edit 界面使用的实体视图是 group.browse


视图创建的没问题吧?还是同样的问题

如果严格按照文档走下来,应该没有问题。
方便的话共享一个测试项目,我们可以帮你看看。

文件9.8M,无法上传。已上传百度网盘
链接:https://pan.baidu.com/s/1YINn2IE33vCsZUHlRYdKcQ
提取码:2u8c

使用zipProject 打包项目并上传。一般项目不会很大。

同样的问题你看下是找不到 Cannot get unfetched attribute [phone] 还是找不到Cannot get unfetched attribute [parent]。
我看你截图的view定义没有勾上parent, parent是原来界面需要的。

这选择 group.browse

MyApp.rar (114.0 KB)

这是我的工程,不知道能不能解决?

改一下这里

好的,非常感谢!