org.hibernate.ObjectDeletedException: deleted obje

org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [ac.iie.dsm.db.model.PlatformUser#1]

 at org.hibernate.internal.SessionImpl.forceFlush(SessionImpl.java:1236)

 at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:187)

 at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:114)

 at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)

 at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:684)

 at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:676)

 at org.hibernate.engine.spi.CascadingActions$5.cascade(CascadingActions.java:235)

 at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:350)

 at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:293)

 at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:161)

 at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:379)

 at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:319)

 at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:296)

 at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:161)

 at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:118)

 at org.hibernate.event.internal.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:167)

 at org.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:158)

 at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:91)

 at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:55)

 at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1222)

 at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:425)

 at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)

 at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)

 at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:555)

 at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)

 at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)

 at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:478)

 at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272)

 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)

 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)

 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

 at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)

 at ac.iie.dsm.service.impl.PlatformUserServiceImpl$$EnhancerBySpringCGLIB$$ee0c45e2.delete(<generated>)

 at ac.iie.dsm.web.controller.PlatformController.delete(PlatformController.java:185)

 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

 at java.lang.reflect.Method.invoke(Unknown Source)

 at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)

 at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)

 at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)

 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)

 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)

 at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)

 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)

 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)

 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)

 at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)

 at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)

 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)

 at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)

 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)

 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)

 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)

 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)

 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)

 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)

 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)

 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)

 at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2476)

 at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2465)

 at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

 at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

 at java.lang.Thread.run(Unknown Source)

PlatformRole.java

@Entity
@Table(name = "dsm_ROLE")
public class PlatformRole extends DsmObject {
 @Id
 @GeneratedValue(strategy = GenerationType.AUTO)
 @Column
 private Integer role_id;
 @Column
 private String role_name;
 @Column
 private Integer role_class;
 @ManyToMany(mappedBy = "roles",fetch = FetchType.EAGER,cascade = CascadeType.ALL)
 private Set<PlatformUser> users = new HashSet<>();
 // 饥渴加载,在管理角色同时能够加载出相应的权限
 @ManyToMany(fetch = FetchType.EAGER,cascade = CascadeType.MERGE)
 @JoinTable(name = "dsm_role_pri", joinColumns = { @JoinColumn(name = "rid") }, inverseJoinColumns = { @JoinColumn(name = "pid") })
 private Set<PlatformPrivilege> pris;
 public Integer getRole_id() {
  return role_id;
 }
 public void setRole_id(Integer role_id) {
  this.role_id = role_id;
 }
 public String getRole_name() {
  return role_name;
 }
 public void setRole_name(String role_name) {
  this.role_name = role_name;
 }
 public Integer getRole_class() {
  return role_class;
 }
 public void setRole_class(Integer role_class) {
  this.role_class = role_class;
 }
 public PlatformRole(Integer role_id, String role_name, Integer role_class) {
  super();
  this.role_id = role_id;
  this.role_name = role_name;
  this.role_class = role_class;
 }
 public PlatformRole() {
 }
 public Set<PlatformUser> getUsers() {
  return users;
 }
 public void setUsers(Set<PlatformUser> users) {
  this.users = users;
 }
 public Set<PlatformPrivilege> getPris() {
  return pris;
 }
 public void setPris(Set<PlatformPrivilege> pris) {
  this.pris = pris;
 }
}

PlatformUser.java

@Entity
@Table(name = "dsm_USER")
public class PlatformUser extends DsmObject {
 @Id
 @GeneratedValue(strategy = GenerationType.AUTO)
 @Column
 private Integer userid;
 @Column
 private String username;
 @Column
 private String password;
 @Column
 private String work_id;
 @ManyToOne(cascade = {CascadeType.MERGE}, fetch = FetchType.EAGER)
 @JoinColumn(name = "org_id")
 private PlatformOrganization org_id;
 // 饥渴加载,在加载用户信息同时加载角色信息
 @ManyToMany(fetch = FetchType.EAGER,cascade = {CascadeType.MERGE})
 @JoinTable(name = "dsm_user_role", joinColumns = { @JoinColumn(name = "userid") }, inverseJoinColumns = { @JoinColumn(name = "rid") })
 private Set<PlatformRole> roles = new HashSet<>();
 @Column
 private String telephone;
 public Integer getUserid() {
  return userid;
 }
 public void setUserid(Integer userid) {
  this.userid = userid;
 }
 public String getUsername() {
  return username;
 }
 public void setUsername(String username) {
  this.username = username;
 }
 public String getPassword() {
  return password;
 }
 public void setPassword(String password) {
  this.password = password;
 }
 public Set<PlatformRole> getRoles() {
  return roles;
 }
 public void setRoles(Set<PlatformRole> roles) {
  this.roles = roles;
 }
 public String getWork_id() {
  return work_id;
 }
 public void setWork_id(String work_id) {
  this.work_id = work_id;
 }
 public PlatformOrganization getOrg_id() {
  return org_id;
 }
 public void setOrg_id(PlatformOrganization org_id) {
  this.org_id = org_id;
 }
 public String getTelephone() {
  return telephone;
 }
 public void setTelephone(String telephone) {
  this.telephone = telephone;
 }
 public PlatformUser() {
 }
}

修改的地方为:将PlatformRole中的users 加载设置为lazy

@ManyToMany(mappedBy = "roles",fetch = FetchType.LAZY,cascade = CascadeType.ALL)

 private Set<PlatformUser> users = new HashSet<>();
时间: 2024-10-12 00:25:33

org.hibernate.ObjectDeletedException: deleted obje的相关文章

Hibernate之deleted object would be re-saved by casc

在Hibernate中,删除存在关联关系的一个对象时,会出现 org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations)这个异常 解决方案如下: 方法1 删除Set方的cascade 方法2 解决关联关系后,再删除 : //移除关联关系 webSite.getTemplates().remove(templat

hibernate中&ldquo;deleted object would be re-saved by cascade&rdquo;异常原理和解决方案

    在hibernate中,经常会出现one to many的关系,如果在不删除one端的前提下要删除many端的某一条或某几条记录,就可能出现上述的异常.     该异常的原理是因为one 端和 many端的联系没有切断,必须要切断他们之间的联系才能进行删除.     方法:     Student s =  studentDao.findById(1);     School.getStudents().remove(s);     s.setSchool(null);     stue

Hibernate的数据删除,更改

一.数据的删除 方法1.从“多”的一方进行数据的删除 books.hbm.xml文件不变: <many-to-one name="publishers" column="publisherId" class="com.entry.Publishers" lazy="false" cascade="save-update"/> publishers.hbm.xml文件: <set name=

spring+hibernate常见异常集合

spring+hibernate出错小结: (1)java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext 原因:出现这错误时,请更改hibernate的包,更新至最新或3.1以上 (2)java.lang.NoClassDefFoundError: javax/transaction/TransactionManager 原因:缺少jta.jar 或者是找不到hbm.xml文件导致sessionfac

Hibernate常见错误整理

Hibernate常见错误合集 1.错误:object references an unsaved transient instance - save the transient instance before flushing: com.xxxx.bean.java.Sysblog; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instanc

hibernate 的配置 cascade

在hibernate中删除一对多中的多方数据时报错: org.hibernate.ObjectDeletedException : deleted object would be re-saved by cascade (remove deleted object from associations): [pojos.UdData#40288669477c2dd501477c2dd6140002] 分析: 字面意思是“被删除的数据因为cascade选项将会被重新保存[方法:将该数据从关联关系中移

Java报错原因汇总

1. java.lang.nullpointerexception 这个异常大家肯定都经常遇到,异常的解释是"程序 遇上了空指针",简单地说就是调用了未经初始化的对象或者是不存在的对象,这个错误经常出现在创建图片,调用数组这些操作中,比如图片 未经初始化,或者图片创建时的路径错误等等.对数组操作中出现空指针,很多情况下是一些刚开始学习编程的朋友常犯的错误,即把数组的初始化和数组元素的初 始化混淆起来了.数组的初始化是对数组分配需要的空间,而初始化后的数组,其中的元素并没有实例化,依然是

Java异常处理总结Exception\Error

Java异常处理总结Exception\Error 2012-12-28 08:17:17|  分类: JAVA |  标签:java  |举报|字号 订阅 Java异常处理总结 异常处理是程序设计中一个非常重要的方面,也是程序设计的一大难点,从C开始,你也许已经知道如何用if...else...来控制异常了,也许是自发的,然而这种控制异常痛苦,同一个异常或者错误如果多个地方出现,那么你每个地方都要做相同处理,感觉相当的麻烦! Java语言在设计的当初就考虑到这些问题,提出异常处理的框架的方案,

权限删除报错

1.错误描述    Caused by:org.hibernate.ObjectDeletedException:deleted object would be re-saved by cascade (remove deleted object from associations); 2.错误原因 3.解决办法 权限删除报错,布布扣,bubuko.com