merge()上的NullPointerException

时间:2010-02-03 10:57:38

标签: hibernate nullpointerexception

我又有一个休眠问题。通过merge()将新实体添加到持久化集合时,我从Hibernate内部的某处获得NullPointerException

这是堆栈跟踪:

java.lang.NullPointerException
    at org.hibernate.type.AbstractType.getHashCode(AbstractType.java:136)
    at org.hibernate.type.AbstractType.getHashCode(AbstractType.java:144)
    at org.hibernate.type.EntityType.getHashCode(EntityType.java:312)
    at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:212)
    at org.hibernate.engine.EntityKey.generateHashCode(EntityKey.java:126)
    at org.hibernate.engine.EntityKey.<init>(EntityKey.java:70)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:147)
    at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:714)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:696)
    at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:268)
    at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:291)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:239)
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:192)
    at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:319)
    at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:265)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:242)
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:192)
    at org.hibernate.engine.Cascade.cascade(Cascade.java:153)
    at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:479)
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:246)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:170)
    at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:714)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:696)
    at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:268)
    at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:291)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:239)
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:192)
    at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:319)
    at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:265)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:242)
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:192)
    at org.hibernate.engine.Cascade.cascade(Cascade.java:153)
    at org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:459)
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:318)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:167)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:81)
    at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:704)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:688)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:692)
    at org.springframework.orm.hibernate3.HibernateTemplate$23.doInHibernate(HibernateTemplate.java:817)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
    at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
    at org.springframework.orm.hibernate3.HibernateTemplate.merge(HibernateTemplate.java:813)
    at com.os.osinventory.database.dao.InventoryDAOImpl.addOrUpdate(InventoryDAOImpl.java:33)
    at com.os.osinventory.gui.annotatedcontroller.InventoryController.saveInventory(InventoryController.java:163)
    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.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    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:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    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:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)

我在两者中都覆盖了hashCode()和equals(),集合保持父项是子实体......

Antoher奇怪的是,saveOrUpdate()给了我一个

org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session:

0 个答案:

没有答案