本帖最后由 J2EE_ME 于 2010-06-23 20:00:53 编辑

解决方案 »

  1.   

    我只想update B这个表,但是没办法传入另外一个条件,所以老是update失败,求高手指教,谢谢。
      

  2.   

    就是说,我想更新一个表,但是这个表没有主键,里面有两条记录UserPurchase(B)
    UserID,PurchaseID,Status,ReceiptNo
    001     1001      ok     000000001
    002     1002      pending null正确的执行脚本应该是
    update UserPurchase set status= 'failed' where UserID = '001' and PurchaseID= '1001'
    但是,因为没有主键,而在entity里,hibernate又一定要我定义主键,否则没法发布,所以我只好指定UserID是主键(其实根本没主键),问题出现了,在我调用getHibernateTemplate().save(UserPurchase)的时候,SQL是
    update UserPurchase set status= 'failed' where UserID = '001' 
    而不是我想要的
    update UserPurchase set status= 'failed' where UserID = '001' and PurchaseID= '1001'所以报错啦。
    Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1
      

  3.   

    因为hibernate的hql在where后面条件只有一个,这样update的话会有两个记录,所以报错,我不知道怎么能把另外一个条件也加进去。
    update UserPurchase set status= 'failed' where UserID = '001' 
    变成我我想要的
    update UserPurchase set status= 'failed' where UserID = '001' and PurchaseID= '1001'
      

  4.   

    where后面的条件为什么只有一个?
      

  5.   

    我也不知道啊,我猜是 我只指定了一个主键(其实也不是,但是必须要指定),hibernate就默认用update UserPurchase set status= 'failed' where UserID = '001'  
      

  6.   

    这样问吧,有没有懂怎么用注解来做hibernate的联合主键呢?
      

  7.   

    自己解决了,结贴。
    用@Embeddable