Hi,
Im trying to create a an Edit Screen only where I have an entity as such:
package com.test.entity;
@Table(name = "TEST_MASTER")
@Entity(name = "test_Master")
@NamePattern("%s|name")
public class Master extends StandardEntity {
private static final long serialVersionUID = 8481454791232333969L;
@NotNull
@Column(name = "NAME", nullable = false)
private String name;
@Temporal(TemporalType.DATE)
@NotNull
@Column(name = "DATE_OF_BIRTH", nullable = false)
private Date dateOfBirth;
@NotNull
@OneToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "USER_ID")
private User user;
@Composition
@OnDelete(DeletePolicy.CASCADE)
@OneToMany(mappedBy = "master")
private List<Detail> detail;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public List<Detail> getDetail() {
return detail;
}
public void setDetail(List<Detail> detail) {
this.detail = detail;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
And
@Table(name = "TEST_DETAIL")
@Entity(name = "test_Detail")
public class Detail extends StandardEntity {
private static final long serialVersionUID = -1530523758606677213L;
@NotNull
@Column(name = "EDUCATION_LEVEL", nullable = false)
private String educationLevel;
@NotNull
@Column(name = "SCHOOL", nullable = false)
private String school;
@Column(name = "YEAR_", nullable = false)
@NotNull
private Integer year;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "MASTER_ID")
private Master master;
public Master getMaster() {
return master;
}
public void setMaster(Master master) {
this.master = master;
}
public Integer getYear() {
return year;
}
public void setYear(Integer year) {
this.year = year;
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public String getEducationLevel() {
return educationLevel;
}
public void setEducationLevel(String educationLevel) {
this.educationLevel = educationLevel;
}
}
The screen is configured as such:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><window xmlns="http://schemas.haulmont.com/cuba/screen/window.xsd" xmlns:c="http://schemas.haulmont.com/cuba/screen/jpql_condition.xsd" caption="msg://masterEditProfile.caption" focusComponent="form" messagesPack="com.test.web.screens.master.single"> <data> <instance id="masterDc" class="com.test.entity.Master" view="master-view"> <loader id="masterDl"> <query> <![CDATA[select e from test_Master e]]> <condition> <c:jpql> <c:where>e.user = :userId</c:where> </c:jpql> </condition> </query> </loader> <collection id="detailDc" property="detail"/> </instance> </data> <dialogMode height="600" width="800"/> <layout expand="editActions" spacing="true"> <form id="form" dataContainer="masterDc"> <column width="350px"> <textField id="nameField" property="name"/> <dateField id="dateOfBirthField" property="dateOfBirth"/> <pickerField id="userField" property="user"> <actions> <action id="lookup" type="picker_lookup"/> <action id="clear" type="picker_clear"/> </actions> </pickerField> </column> </form> <groupBox id="detailBox" caption="msg://com.test.entity/Master.detail"> <table id="detailTable" dataContainer="detailDc" width="100%" height="200px"> <actions> <action id="create" type="create"/> <action id="edit" type="edit"/> <action id="remove" type="remove"/> </actions> <columns> <column id="educationLevel"/> <column id="school"/> <column id="year"/> </columns> <buttonsPanel> <button action="detailTable.create"/> <button action="detailTable.edit"/> <button action="detailTable.remove"/> </buttonsPanel> </table> </groupBox> <hbox id="editActions" spacing="true"> <button id="commitAndCloseBtn" action="windowCommitAndClose"/> <button id="closeBtn" action="windowClose"/> <button id="enableEditing" action="enableEditing"/> </hbox> </layout> </window>
with the controller:
@UiController("test_Master.editProfile")
@UiDescriptor("master-edit-profile.xml")
@EditedEntityContainer("masterDc")
@LoadDataBeforeShow
public class MasterEditProfile extends StandardEditor<Master> {
@Inject
private InstanceLoader<Master> masterDl;
@Inject
private UserSession userSession;
@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
masterDl.setParameter("userId", userSession.getCurrentOrSubstitutedUser());
masterDl.load();
}
@Subscribe
public void onInit(InitEvent event) {
this.setReadOnly(true);
}
}
This is the screen Result:
But when I update the data I get the following error:
16:13:38.272 ERROR c.h.cuba.core.sys.ServiceInterceptor - Exception:
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.3.16-cuba): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: null value in column "name" violates not-null constraint
Detail: Failing row contains (04cfc33d-94d1-3aa7-fc65-b646af5af336, 1, 2021-08-02 16:13:38.126, john, 2021-08-02 16:13:38.126, null, null, null, null, null, null).
Error Code: 0
Call: INSERT INTO TEST_MASTER (ID, CREATE_TS, CREATED_BY, DATE_OF_BIRTH, DELETE_TS, DELETED_BY, NAME, UPDATE_TS, UPDATED_BY, VERSION, USER_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [04cfc33d-94d1-3aa7-fc65-b646af5af336, 2021-08-02 16:13:38.126, john, null, null, null, null, 2021-08-02 16:13:38.126, null, 1, null]
Query: InsertObjectQuery(com.test.entity.Master-04cfc33d-94d1-3aa7-fc65-b646af5af336 [new,managed])
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:979) ~[org.eclipse.persistence.jpa-2.7.3-16-cuba.jar:na]
at com.haulmont.cuba.core.sys.persistence.PersistenceImplSupport$ContainerResourceSynchronization.detachAll(PersistenceImplSupport.java:504) ~[cuba-core-7.2.14.jar:7.2.14]
at com.haulmont.cuba.core.sys.persistence.PersistenceImplSupport$ContainerResourceSynchronization.beforeCommit(PersistenceImplSupport.java:450) ~[cuba-core-7.2.14.jar:7.2.14]
at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:96) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:919) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:727) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:711) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at com.haulmont.cuba.core.sys.TransactionImpl.commit(TransactionImpl.java:104) ~[cuba-core-7.2.14.jar:7.2.14]
at com.haulmont.cuba.core.app.RdbmsStore.commit(RdbmsStore.java:561) ~[cuba-core-7.2.14.jar:7.2.14]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_202]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_202]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_202]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_202]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:62) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at com.sun.proxy.$Proxy321.commit(Unknown Source) ~[na:na]
at com.haulmont.cuba.core.app.DataManagerBean.commit(DataManagerBean.java:188) ~[cuba-core-7.2.14.jar:7.2.14]
at com.haulmont.cuba.core.app.DataServiceBean.commit(DataServiceBean.java:41) ~[cuba-core-7.2.14.jar:7.2.14]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_202]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_202]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_202]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_202]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at com.haulmont.cuba.core.sys.ServiceInterceptor.aroundInvoke(ServiceInterceptor.java:90) ~[cuba-core-7.2.14.jar:7.2.14]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_202]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_202]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_202]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_202]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) [spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at com.sun.proxy.$Proxy220.commit(Unknown Source) [na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_202]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_202]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_202]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_202]
at com.haulmont.cuba.core.sys.remoting.LocalServiceInvokerImpl.invoke(LocalServiceInvokerImpl.java:94) [cuba-core-7.2.14.jar:7.2.14]
at com.haulmont.cuba.web.sys.remoting.LocalServiceProxy$LocalServiceInvocationHandler.invoke(LocalServiceProxy.java:159) [cuba-web-7.2.14.jar:7.2.14]
at com.sun.proxy.$Proxy34.commit(Unknown Source) [na:na]
at com.haulmont.cuba.client.sys.DataManagerClientImpl.commit(DataManagerClientImpl.java:100) [cuba-client-7.2.14.jar:7.2.14]
at com.haulmont.cuba.gui.model.impl.DataContextImpl.commitToDataManager(DataContextImpl.java:686) [cuba-gui-7.2.14.jar:7.2.14]
at com.haulmont.cuba.gui.model.impl.DataContextImpl.performCommit(DataContextImpl.java:664) [cuba-gui-7.2.14.jar:7.2.14]
at com.haulmont.cuba.gui.model.impl.DataContextImpl.commit(DataContextImpl.java:627) [cuba-gui-7.2.14.jar:7.2.14]
at com.haulmont.cuba.gui.screen.StandardEditor.lambda$commitChanges$5(StandardEditor.java:423) [cuba-gui-7.2.14.jar:7.2.14]
at com.haulmont.cuba.gui.screen.StandardEditor.commitChanges(StandardEditor.java:451) [cuba-gui-7.2.14.jar:7.2.14]
at com.haulmont.cuba.gui.screen.StandardEditor.closeWithCommit(StandardEditor.java:600) [cuba-gui-7.2.14.jar:7.2.14]
at com.haulmont.cuba.gui.screen.StandardEditor.commitAndClose(StandardEditor.java:566) [cuba-gui-7.2.14.jar:7.2.14]
at com.haulmont.bali.events.EventHub.publish(EventHub.java:170) ~[cuba-global-7.2.14.jar:7.2.14]
at com.haulmont.cuba.gui.components.actions.BaseAction.actionPerform(BaseAction.java:222) ~[cuba-gui-7.2.14.jar:7.2.14]
at com.haulmont.cuba.web.gui.components.WebButton.buttonClicked(WebButton.java:67) ~[cuba-web-7.2.14.jar:7.2.14]
at com.haulmont.cuba.web.widgets.CubaButton.fireClick(CubaButton.java:76) ~[cuba-web-widgets-7.2.14.jar:na]
at com.vaadin.ui.Button$1.click(Button.java:57) ~[vaadin-server-8.9.2-26-cuba.jar:8.9.2-26-cuba]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_202]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_202]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_202]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_202]
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:153) ~[vaadin-server-8.9.2-26-cuba.jar:8.9.2-26-cuba]
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:115) ~[vaadin-server-8.9.2-26-cuba.jar:8.9.2-26-cuba]
at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:431) ~[vaadin-server-8.9.2-26-cuba.jar:8.9.2-26-cuba]
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:396) ~[vaadin-server-8.9.2-26-cuba.jar:8.9.2-26-cuba]
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:260) ~[vaadin-server-8.9.2-26-cuba.jar:8.9.2-26-cuba]
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:82) ~[vaadin-server-8.9.2-26-cuba.jar:8.9.2-26-cuba]
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40) ~[vaadin-server-8.9.2-26-cuba.jar:8.9.2-26-cuba]
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1580) ~[vaadin-server-8.9.2-26-cuba.jar:8.9.2-26-cuba]
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:425) ~[vaadin-server-8.9.2-26-cuba.jar:8.9.2-26-cuba]
at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:329) ~[cuba-web-7.2.14.jar:7.2.14]
at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:215) ~[cuba-web-7.2.14.jar:7.2.14]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[servlet-api.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[catalina.jar:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[catalina.jar:9.0.38]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-websocket.jar:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[catalina.jar:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[catalina.jar:9.0.38]
at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:108) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:74) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:93) ~[cuba-web-7.2.14.jar:7.2.14]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[catalina.jar:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[catalina.jar:9.0.38]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[catalina.jar:9.0.38]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[catalina.jar:9.0.38]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[catalina.jar:9.0.38]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) ~[catalina.jar:9.0.38]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[catalina.jar:9.0.38]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690) ~[catalina.jar:9.0.38]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[catalina.jar:9.0.38]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[catalina.jar:9.0.38]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) ~[tomcat-coyote.jar:9.0.38]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-coyote.jar:9.0.38]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-coyote.jar:9.0.38]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) ~[tomcat-coyote.jar:9.0.38]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-coyote.jar:9.0.38]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_202]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_202]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-util.jar:9.0.38]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_202]
What did I do wrong?
What is the proper way of doing this ?
Can anyone advise on this
Thank you very much in advance