HibernateSystemException:未知实体:org.hibernate.collection.PersistentSet;

时间:2012-03-06 08:03:13

标签: hibernate

我的目标是实现删除所有建议然后插入新建议。 (任何在线示例都会有很大的帮助。

hbm映射如下:

<set name="recommendations" table="PRD_PRODUCT_RECOMMENDATION" 
inverse="true" lazy="true" batch-size="25" fetch="select" cascade="save-update, delete">
 <cache usage="nonstrict-read-write"/>   
  <key column="productguid" not-null="true"/>
  <one-to-many class="com.quinstreet.persistence.productCatalogue.ProductRecommendationDBVO" />
</set>

我使用以下代码删除建议:

     ProductDBVO dbvo =((ProductImpl)product).getProductDBVO();
     Set<ProductRecommendationDBVO> recommendations= dbvo.getRecommendations(); 
     dbvo.getRecommendations().remove(recommendations);
      getHibernateTemplate().saveOrUpdate(recommendations);
getSession().flush();
      getSession().refresh(((ProductImpl)product).getProductDBVO());

并收到错误:

org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity:    org.hibernate.collection.PersistentSet; nested exception is org.hibernate.MappingException: Unknown entity: org.hibernate.collection.PersistentSet
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:659)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:378)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:791)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:787)
at com.quinstreet.persistence.product.ProductDAOHibImpl.deleteRecommendations(ProductDAOHibImpl.java:2564)
at com.quinstreet.service.product.ProductServiceImpl.updateCatalogue(ProductServiceImpl.java:1827)
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:301)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy36.updateCatalogue(Unknown Source)
at com.quinstreet.app.admin.productCatalogue.struts.actions.viewprep.UpdateProductAttributesAction.executeModelUpdate(UpdateProductAttributesAction.java:38)
at com.quinstreet.app.admin.ProductAdminModelUpdateAction.executeAction(ProductAdminModelUpdateAction.java:43)
at com.quinstreet.app.framework.actions.CoreStrutsConstrainedAction.executeAction(CoreStrutsConstrainedAction.java:135)
at com.quinstreet.app.framework.actions.CoreStrutsAction.execute(CoreStrutsAction.java:120)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at com.quinstreet.app.framework.CoreStrutsActionServlet.process(CoreStrutsActionServlet.java:108)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
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.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:292)
at com.quinstreet.app.framework.filters.RedirectAfterPostFilter.doFilterInternal(RedirectAfterPostFilter.java:106)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:84)
at net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter.doFilter(SecurityEnforcementFilter.java:182)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at net.sf.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:153)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at com.quinstreet.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:354)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:225)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at net.sf.acegisecurity.securechannel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:168)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at net.sf.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:173)
at net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:125)
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.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.hibernate.MappingException: Unknown entity:   org.hibernate.collection.PersistentSet
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:580)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1365)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:100)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:793)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:771)
at org.springframework.orm.hibernate3.HibernateTemplate$25.doInHibernate(HibernateTemplate.java:797)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:373)

请咨询

由于

1 个答案:

答案 0 :(得分:6)

saveOrUpdate()将实体作为参数。但是你传递了一组我认为是实体的对象。

您无需saveOrUpdate附加到会话的内容。 saveOrUpdate用于保留新实体,或更新现有但已分离的实体。

要删除集合中的所有元素,只需将它们从集合中删除,Hibernate将自动执行该持久化:

product.getRecommendations().clear();

就是你所需要的一切。