2012-12-11 64 views
2

我在嘗試保存實體時出現錯誤。我在啓動服務器時只遇到這個錯誤,而不是當我使用dbunit運行我的單元測試時。org.hibernate.event.def.EventCache不支持null實體是什麼意思?

我正在嘗試保存關聯。我的單元測試應該與手動測試時遇到的完全相同。我在關係的一端添加了一個新的實體,這種關係之前沒有任何關係。

我正在使用HSQLDB進行單元測試,並且Web應用程序正在使用SQL Server。

我已經完成的搜索沒有證明有效果。對該信息的解釋將非常有用。

這裏是測試用例(即工作就好了!):

@Test 
     @DatabaseSetup(value="MobileWebsiteTest.saveMobilewebsiteMobilecolorswatchmapuserdefined_NewUserSwatch.xml", type=DatabaseOperation.REFRESH) 
    public void saveMobilewebsiteMobilecolorswatchmapuserdefined_NewUserSwatch() { 
     // given 
     Integer mobileWebsiteId = 569; 
     Mobilecolorswatchmapuserdefined expected = MobilecolorswatchmapuserdefinedBuilder.init().build(); 

     // when 
     Mobilewebsite result = service.saveMobilewebsiteMobilecolorswatchmapuserdefined(mobileWebsiteId, expected); 

     // then 
     assertNotNull("The Mobilewebsite user defined swatch should not be null", result.getMobilecolorswatchmapuserdefined()); 
     assertNotNull("The Mobilewebsite user defined swatch id should not be null.", result.getMobilecolorswatchmapuserdefined().getMobileColorSwatchMapUserDefinedId()); 
     assertEquals("The result aside property should be equivalent to the expected aside property.", expected.getAside(), result.getMobilecolorswatchmapuserdefined().getAside()); 
     assertEquals("The result SiteName property should be equivalent to the expected SiteName property.", expected.getSiteName(), result.getMobilecolorswatchmapuserdefined().getSiteName()); 
    } 

這裏的服務(注:我目前在做刪除/保存已經存在關聯的情況下 - 這應該是一到一個,但是傳統):

@Override 
@Transactional 
public Mobilewebsite saveMobilewebsiteMobilecolorswatchmapuserdefined(Integer mobileWebsiteId, Mobilecolorswatchmapuserdefined related_swatchmap) { 
    log.debug("saveMobilewebsiteMobilecolorswatchmapuserdefined(Integer mobileWebsiteId=[" + mobileWebsiteId + "], Mobilecolorswatchmapuserdefined related_swatchmap=[" + related_swatchmap + "])"); 

    Mobilewebsite mobilewebsite = mobilewebsiteDAO.findMobilewebsiteByPrimaryKey(mobileWebsiteId, -1, -1); 
    Calendar now = Calendar.getInstance(); 

    if (mobilewebsite.getMobilecolorswatchmapuserdefined() != null) { 
     this.deleteMobilewebsiteMobilecolorswatchmapuserdefined(mobilewebsite.getMobileWebsiteId(), mobilewebsite.getMobilecolorswatchmapuserdefined().getMobileColorSwatchMapUserDefinedId()); 
    } 

    related_swatchmap.setCreatedDtstamp(now); 
    related_swatchmap.setLastUpdatedDtstamp(now); 

    related_swatchmap.addToMobilewebsites(mobilewebsite); 
    **related_swatchmap = mobilecolorswatchmapuserdefinedDAO.store(related_swatchmap);** 

    mobilewebsite.setMobilecolorswatchmapuserdefined(related_swatchmap); 
    mobilewebsite = mobilewebsiteDAO.store(mobilewebsite); 
    mobilewebsiteDAO.flush(); 

    return mobilewebsite; 
} 

堆棧跟蹤點上面的突出顯示的行:mobilecolorswatchmapuserdefinedDAO.store(related_swatchmap);

的堆棧跟蹤是:

2012-12-11 15:14:11.192 59464 [http-8080-2] ERROR - Unexpected error occurred 
org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at [ [Component id = form1]] on component [ [Component id = form1]] threw an exception 
    at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:270) 
    at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216) 
    at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:248) 
    at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234) 
    at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:781) 
    at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) 
    at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:255) 
    at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212) 
    at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:283) 
    at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:185) 
    at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:241) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) 
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) 
    at java.lang.Thread.run(Thread.java:662) 
Caused by: java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:260) 
    ... 22 more 
**Caused by: java.lang.NullPointerException: null entities are not supported by org.hibernate.event.def.EventCache** 
    at org.hibernate.event.def.EventCache.containsKey(EventCache.java:80) 
    at org.hibernate.event.def.DefaultMergeEventListener.mergeTransientEntity(DefaultMergeEventListener.java:361) 
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:303) 
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:258) 
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:84) 
    at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:859) 
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:843) 
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:847) 
    at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:682) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365) 
    at $Proxy44.merge(Unknown Source) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) 
    at $Proxy44.merge(Unknown Source) 
    at org.skyway.spring.util.dao.AbstractJpaDao.merge(AbstractJpaDao.java:61) 
    at org.skyway.spring.util.dao.AbstractJpaDao.store(AbstractJpaDao.java:48) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
    at $Proxy76.store(Unknown Source) 
    **at com.telventdtn.aghostmobile.service.MobilewebsiteServiceImpl.saveMobilewebsiteMobilecolorswatchmapuserdefined(MobilewebsiteServiceImpl.java:342)** 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
    at $Proxy77.saveMobilewebsiteMobilecolorswatchmapuserdefined(Unknown Source) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.apache.wicket.proxy.LazyInitProxyFactory$JdkHandler.invoke(LazyInitProxyFactory.java:416) 
    at org.apache.wicket.proxy.$Proxy4.saveMobilewebsiteMobilecolorswatchmapuserdefined(Unknown Source) 
    at com.telventdtn.aghostmobile.ArrangeColorsThemePage$SubmitButtonHandler.onSubmit(ArrangeColorsThemePage.java:126) 
    at com.telventdtn.aghostmobile.markup.html.form.ObservableButton.notifyObservers(ObservableButton.java:20) 
    at com.telventdtn.aghostmobile.markup.html.form.ButtonFactory$1.onSubmit(ButtonFactory.java:34) 
    at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1151) 
    at org.apache.wicket.markup.html.form.Form.process(Form.java:834) 
    at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:762) 
    at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:692) 
    ... 27 more 
+0

我會添加代碼,但因爲我甚至不知道什麼異常可能意味着,我不知道我應該包括什麼代碼。 –

+0

您可以先發布與您的堆棧跟蹤錯誤相關的代碼:) –

回答

5

我有其中所述表中定義的nullable列,但域類將其標記爲not nullable類似的經歷。試圖用nulls保存對象,事實上它仍然存在,但是隨後出現錯誤。希望這可以幫助。

+1

聽起來很奇怪,這也是我們的問題。註解表示可空= false,而db模式允許爲空。我們的數據有一個空值,不知何故未被驗證捕獲。修復註釋或修復數據解決了問題。 – skipwalker

相關問題