JPA 2.0 null在flush操作时从mappedsuperclass继承了字段

时间:2017-04-05 16:20:13

标签: java oracle jpa eclipselink mappedsuperclass

我有以下层次结构

@MappedSuperclass
public class MensajeErrorBase{

@Enumerated(EnumType.STRING)
@Column(name = "SEVERIDAD", nullable = false, length = 50)
protected EnumSeveridadMensaje severidad;
//...
}

@Entity
@Table(name = "TRA_INGRE_IDENTI_MSJ")
public class IngresoPorIdentificarMsg extends MensajeErrorBase implements    Serializable, MensajeMonitoreo {

private static final long serialVersionUID = -8722933693750515329L;

@EmbeddedId
protected IngresoPorIdentificarMsgPK pk;
//...
}

和我执行crud操作的transctional ejb。 在另一个名为ServicioProceso的ejb中,我有以下方法:

private <T extends MensajeErrorBase> void guardarMensajesError(Class<T> claseEntidad, Serializable pk, List<T> listaMensajes,
                DatoSesionAud dsa) {
            try {
                MensajeMonitoreo msjMonitoreo = (MensajeMonitoreo) claseEntidad.newInstance();
                if (msjMonitoreo.getClaseMsjParam() == null) {
                    throw new RuntimeException(excepcionNosePropago(ServicioProceso.class, "guardarMensajesError",
                            "No estan configurados los metodos que retornan las clases de parametros en la clase de Mensajes Base"));
                }
                for (MensajeErrorBase mensajeErrorBase : listaMensajes) {
                    msjMonitoreo = (MensajeMonitoreo) mensajeErrorBase;
                    msjMonitoreo.setClavePrimaria((Serializable) BeansUtil.deepClone(pk));
                    super.insertSecuencia(msjMonitoreo, dsa);
                    List<MensajeErrorParamBase> listaMensajesParam = ((MensajeMonitoreo) mensajeErrorBase).getParametros();
                    for (int i = 1; i <= listaMensajesParam.size(); i++) {
                        MensajeMonitoreoParam msjMonitoreoParam = (MensajeMonitoreoParam) listaMensajesParam.get(i - 1);
                        msjMonitoreoParam.setClavePrimaria((Serializable) BeansUtil.deepClone(msjMonitoreo.getPk()), i);
                        super.insert(msjMonitoreoParam, dsa);
                        List<MensajeErrorParamParamBase> listaMensajesParamParam =
                                ((MensajeMonitoreoParam) listaMensajesParam.get(i - 1)).getParametros();
                        for (int j = 1; j <= listaMensajesParamParam.size(); j++) {
                            MensajeMonitoreoParamParam msjMonitoreoParamParam =
                                    (MensajeMonitoreoParamParam) listaMensajesParamParam.get(j - 1);
                            msjMonitoreoParamParam.setClavePrimaria((Serializable) BeansUtil.deepClone(msjMonitoreoParam.getPk()), j);
                            super.insert(msjMonitoreoParamParam, dsa);
                        }
                    }
                    super.flush();
                }
            } catch (InstantiationException | IllegalAccessException e) {
                LoggerUtil.runtimeException(e, ServicioProceso.class);
                throw new RuntimeException(excepcionNosePropago(ServicioProceso.class, "guardarMensajesError", e));
            }
        }

行:

 super.insertSecuencia(msjMonitoreo, dsa);

调用执行crud操作的ejb,并使用映射的超类和子类的所有数据发送对象 msjMonitoreo 。但在刷新调用中,我得到以下异常:

[4/5/17 10:52:05:995 ECT] 00000093 SystemOut     O [EL Warning]: 2017-04-05 10:52:05.994--UnitOfWork(-1281205041)--Thread(Thread[WebContainer : 3,5,main])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into ("SANTANDER_DESA"."TRA_INGRE_IDENTI_MSJ"."SEVERIDAD")

Error Code: 1400
Call: INSERT INTO TRA_INGRE_IDENTI_MSJ (ETIQUETA, RECURSO_MULTILENGUAJE, SEVERIDAD, COD_EMPRESA, SECUENCIA, NUM_LICENCIA, SEC_MENSAJE) VALUES (?, ?, ?, ?, ?, ?, ?)
        bind => [null, null, null, E-MPR, 1, 1, 4]
Query: InsertObjectQuery(IngresoPorIdentificarMsg[pk=IngresoPorIdentificarMsgPK[ numLicencia=1,codigoEmpresa=E-MPR,codigoProducto=1,secuenciaMensaje=4]])
[4/5/17 10:52:05:996 ECT] 00000093 BusinessExcep E   CNTR0020E: EJB threw an unexpected (non-declared) exception during invocation of method "registrarMensajesError" on bean "BeanId(GestorG5#G5Core-ejb.jar#ServicioProceso, null)". Exception data: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into ("SANTANDER_DESA"."TRA_INGRE_IDENTI_MSJ"."SEVERIDAD")

Error Code: 1400
Call: INSERT INTO TRA_INGRE_IDENTI_MSJ (ETIQUETA, RECURSO_MULTILENGUAJE, SEVERIDAD, COD_EMPRESA, SECUENCIA, NUM_LICENCIA, SEC_MENSAJE) VALUES (?, ?, ?, ?, ?, ?, ?)
        bind => [null, null, null, E-MPR, 1, 1, 4]
Query: InsertObjectQuery(IngresoPorIdentificarMsg[pk=IngresoPorIdentificarMsgPK[ numLicencia=1,codigoEmpresa=E-MPR,codigoProducto=1,secuenciaMensaje=4]])
        at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:868)
        at com.ibm.ws.jpa.management.JPATxEmInvocation.flush(JPATxEmInvocation.java:255)
        at com.ibm.ws.jpa.management.JPAEntityManager.flush(JPAEntityManager.java:221)
        at com.gestorinc.gestor.crud.impl.CrudServiceImpl.flush(CrudServiceImpl.java:730)
        at com.gestorinc.g5.servicio.impl.general.ServicioProceso.guardarMensajesError(ServicioProceso.java:305)
        at com.gestorinc.g5.servicio.impl.general.ServicioProceso.registrarMensajesError(ServicioProceso.java:115)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
        at java.lang.reflect.Method.invoke(Method.java:620)
        at com.ibm.ejs.container.EJSContainer.invokeProceed(EJSContainer.java:5730)
        at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:568)
        at org.apache.webbeans.ejb.common.interceptor.OpenWebBeansEjbInterceptor.callInterceptorsAndDecorators(OpenWebBeansEjbInterceptor.java:526)
        at org.apache.webbeans.ejb.common.interceptor.OpenWebBeansEjbInterceptor.callToOwbInterceptors(OpenWebBeansEjbInterceptor.java:200)
        at sun.reflect.GeneratedMethodAccessor68.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
        at java.lang.reflect.Method.invoke(Method.java:620)
        at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:227)
        at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:548)
        at org.apache.webbeans.ejb.WSEJBInterceptor.callToOwbInterceptors(WSEJBInterceptor.java:136)
        at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
        at java.lang.reflect.Method.invoke(Method.java:620)
        at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:227)
        at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:548)
        at com.ibm.ejs.container.interceptors.InvocationContextImpl.doAroundInvoke(InvocationContextImpl.java:229)
        at com.ibm.ejs.container.EJSContainer.invoke(EJSContainer.java:5621)
        at com.gestorinc.g5.servicio.impl.general.EJSLocalNSLServicioProceso_bf34d3b4.registrarMensajesError(EJSLocalNSLServicioProceso_bf34d3b4.java)
        at com.gestorinc.g5web.bean.bpm.TareasActividadesBandejaBean.ejecutarErrores(TareasActividadesBandejaBean.java:251)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
        at java.lang.reflect.Method.invoke(Method.java:620)
        at org.apache.webbeans.intercept.InterceptorHandler.invoke(InterceptorHandler.java:297)
        at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:98)
        at com.gestorinc.g5web.bean.bpm.TareasActividadesBandejaBean_$$_javassist_6.ejecutarErrores(TareasActividadesBandejaBean_$$_javassist_6.java)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
        at java.lang.reflect.Method.invoke(Method.java:620)
        at org.apache.el.parser.AstValue.invoke(AstValue.java:268)
        at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
        at org.apache.myfaces.view.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:83)
        at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:78)
        at javax.faces.event.ActionEvent.processListener(ActionEvent.java:51)
        at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:360)
        at javax.faces.component.UICommand.broadcast(UICommand.java:103)
        at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:973)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:275)
        at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1285)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:711)
        at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:34)
        at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:172)
        at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:119)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1227)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:776)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:458)
        at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)
        at com.gestorinc.g5web.filter.FiltroAccesoAutenticado.doFilter(FiltroAccesoAutenticado.java:76)
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
        at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:928)
        at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1025)
        at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
        at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:909)
        at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
        at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:459)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:526)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:312)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:283)
        at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
        at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
        at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
        at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
        at com.ibm.io.async.AsyncChannelFuture$1.run(AsyncChannelFuture.java:205)
        at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1862)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into ("SANTANDER_DESA"."TRA_INGRE_IDENTI_MSJ"."SEVERIDAD")

当我调试时,所有字段都设置了de对应的值。 debug shows that all fields are setted。我的服务器在WebSphere Application Server(完整版)8.5.5.0上运行。但是,当我部署到Liberty WebSphere时,它可以正常工作

2 个答案:

答案 0 :(得分:0)

我仍然不知道发生了什么,但我发现了问题:我在我的耳朵应用程序中打包的库中有两个persistence.xml una,而在ejb模块中有另一个。所以我删除了de ejb模块上的那个,将它的持久性单元放在库的同一个文件中。并且工作正常。我仍然不知道为什么它在自由服务器上工作正常并且在IBM WAS 8.5上失败。 谢谢大家的帮助。

答案 1 :(得分:0)

它不是双persistence.xml它是Glassfish Bug:

https://github.com/javaee/glassfish/issues/16164

我不得不禁用编织:

<properties>
  <!-- Documentation https://www.eclipse.org/eclipselink/documentation/2.5/concepts/app_dev007.htm says its 'eclipse.weaving', but examples say its 'eclipselink.weaving'. Great. -->
  <property name="eclipselink.weaving" value="false"/>
  <property name="eclipse.weaving" value="false"/>
</properties>