<hibernate-mapping package="model">
  <class name="Purpose" table="purpose">
     <id name="id" column="id" type="int">
        <generator class="increment" />
     </id>
     <property name="name" column="name" />
     <many-to-one name="pt" column="typeid" not-null="true" class="model.Type" />
  </class>
</hibernate-mapping> 增加 not-null="true" 看看

解决方案 »

  1.   

    同时,也说明你的数据库设计也有问题,那个typeid 字段不能为null, 就不会有这个问题了!
      

  2.   

    我把数据库purpose里的typeid设为不为空
    .hbm设置为<hibernate-mapping package="model">
      <class name="Purpose" table="purpose">
         <id name="id" column="id" type="int">
            <generator class="increment" />
         </id>
         <property name="name" column="name" />
         <many-to-one name="pt" column="typeid" not-null="true" class="model.Type" />
      </class>
    </hibernate-mapping> 为啥他还是更新这个表,不删除?
      

  3.   

    这东西真难整阿,你能说说控方的Set集合作用是什么吗
      

  4.   

    为啥他还是更新这个表,不删除?证明你的那个数据库表格根本没有设置正确,否则他更新不了,报数据库异常。cascade="all-delete-orphan" 
    改成
    cascade="all" 算了
     
      

  5.   

    谢谢你java2000_net ,我改过cascade="all" 也没用。
    现在情况是它也报错
    org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
      

  6.   

    <set name="pp"  lazy="true" inverse="false" cascade="delete">
      

  7.   

    请参考如下文章
    http://blog.csdn.net/daryl715/archive/2007/12/04/1916179.aspx
      

  8.   

    实在整不明白,报错问题解决了,它就是不删除,只更新,java2000_net谢谢你,如果没有正确答案,分都给你了
      

  9.   

    <set name="pp" inverse="false" cascade="delete">inverse 表示交给inverse="false" 的那一方控制,在此例中,就是在type方设置为false,交给type来维护关系cascade 表示维护关系的级别,"delete"表明是在删除时维护这样说,不知楼主明白了吗?
      

  10.   

    org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException:   Batch   update   returned   unexpected   row   count   from   update:   0   actual   row   count:   0   expected:   1;   nested   exception   is   org.hibernate.StaleStateException:   Batch   update   returned   unexpected   row   count   from   update:   0   actual   row   count:   0   expected:   1应该是所删除的对象没有正确的Id,你可以设个断点看下,要删除对象的Id是你数据库中的Id吗?