以下代码去掉注释后会报异常,但是它的 sql 已经打出来了 ,请大家解惑
    
                             org.hibernate.Session session = getHibernateSession();
Transaction tx = session.beginTransaction();


FmStation po2 =(Station) session.get(FmStation.class,po.getId() );
session.evict(po2);
// po2.setId("008881e5336389f10133639b36690001");
po2.setAano("setid 001---002");

session.saveOrUpdate(po2);
session.flush();
tx.commit();
session.close();
异常:Hibernate: update STATION set AANO=?, COMPANY_ID=?, REGION_ID=?, STATION_CODE=?, STATION_LEVEL=?, STATION_NAME=?, STATION_SHORTHAND=?, STATION_SHORTNAME=? where ID=?
2011-11-02 17:51:24,375 WARN  org.hibernate.util.JDBCExceptionReporter - SQL Error: 2601, SQLState: S0001
2542547 [http-8088-2] WARN  org.hibernate.util.JDBCExceptionReporter  - SQL Error: 2601, SQLState: S0001
2011-11-02 17:51:24,375 ERROR org.hibernate.util.JDBCExceptionReporter - 不能在具有唯一索引 'uq_T_FM_STATION_01' 的对象 'dbo.STATION' 中插入重复键的行。
2542547 [http-8088-2] ERROR org.hibernate.util.JDBCExceptionReporter  - 不能在具有唯一索引 'uq_T_FM_STATION_01' 的对象 'dbo.T_FM_STATION' 中插入重复键的行。
2011-11-02 17:51:24,375 ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not update: [com.newsoft.fui.po.base.FmStation#008881e5336389f10133639b36690001]

解决方案 »

  1.   

    hibernate更新的时候 比如要定义主键 
      

  2.   

    我给主键赋值是因为我想它会生成 update 语句, 目前的情况是update也生成了,但后面的错误我就不知道怎么回事了 
      

  3.   

    你这个主键是用了UUID.hex吧。。
       你看,你首先是去数据库读出这个对象,你需要更改这个对象的属性
    然而,你把这个对象的标识符都改了。。请问,怎么行。。
      

  4.   

    为什么改了标示符不行呢, 我希望用po2的数据来更新id '008881e5336389f10133639b36690001'指向的数据, 这个是我的目的