多对一双向关联删除子类关于临时对象的问题
最近我在项目中加入多对一双向关联的做法 因为以前没涉及过hibernate级联删除问题 我建立了几个多对一关联的双向关联,下面是我的代码:
Customer.hbm.xml
...省略其它Customer属性<set name="msges" inverse="true" cascade="all"><key column="RecCustomer_id"/><one-to-many inverse="true" cascade="all"><key column="SendCustomer_id"/><one-to-many lazy="true" inverse="true" cascade="all"><key column="EricPingLun_id"/><one-to-many name="code">... 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" column="RecCustomer_id" name="code">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这个临时对象