多对一双向关联删除子类关于临时对象的有关问题
多对一双向关联删除子类关于临时对象的问题
最近我在项目中加入多对一双向关联的做法 因为以前没涉及过hibernate级联删除问题 我建立了几个多对一关联的双向关联,下面是我的代码:
Customer.hbm.xml
Customer.java
EricMsg.java
EricMsg.hbm.xml
现在Customer登录后,察看到自己的消息,察看完毕后,想删除掉Ericmsg.可是总是删除的时候出现
有的时候也会出现说
我的 删除 Action中只是把ID传过去 然后利用接口的
我觉得主要的把我获取留言的类贴出来,我自己觉得是这里出了问题
CheckCustomerMsgAction
我改了很多 可是依旧无法解决这个问题,我想达到的是能删除Msg 用户再次Check后不能再看到那条消息,我现在却依旧可以看到msg这个临时对象
最近我在项目中加入多对一双向关联的做法 因为以前没涉及过hibernate级联删除问题 我建立了几个多对一关联的双向关联,下面是我的代码:
Customer.hbm.xml
...省略其它Customer属性 <set name="msges" inverse="true" cascade="all"> <key column="RecCustomer_id"/> <one-to-many class="EricMsg"/> </set> <set name="msgess" inverse="true" cascade="all"> <key column="SendCustomer_id"/> <one-to-many class="EricMsg"/> </set> <set name="ericpingluns" lazy="true" inverse="true" cascade="all"> <key column="EricPingLun_id"/> <one-to-many class="EricPingLun"/> </set> 下面还有几个同样的set属性...
Customer.java
... private Set ericNewses=new HashSet(); //关系 1:n private Set ericpingluns=new HashSet();//关系 1:n
EricMsg.java
... private Customer sendcustomer; private Customer reccustomer;
EricMsg.hbm.xml
<many-to-one name="sendcustomer" column="SendCustomer_id" class="Customer"/> <many-to-one name="reccustomer" column="RecCustomer_id" class="Customer"/>
现在Customer登录后,察看到自己的消息,察看完毕后,想删除掉Ericmsg.可是总是删除的时候出现
deleted object would be re-saved by cascade
有的时候也会出现说
session would be used or session would be closed
我的 删除 Action中只是把ID传过去 然后利用接口的
public void deleteEricMsg(EricMsg ericmsg) throws ServicesException { this.delete(ericmsg); }
我觉得主要的把我获取留言的类贴出来,我自己觉得是这里出了问题
CheckCustomerMsgAction
private Customer customer; private Set ericmsges=new HashSet(); public String execute()throws Exception{ customer=super.getCustomer(); if(this.customer!=null){ if(customer.getMsges().size()>0){ ericmsges=customer.getMsges(); return SUCCESS; } return INPUT; } return INPUT; }
我改了很多 可是依旧无法解决这个问题,我想达到的是能删除Msg 用户再次Check后不能再看到那条消息,我现在却依旧可以看到msg这个临时对象