以下代码去掉注释后会报异常,但是它的 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]
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]
你看,你首先是去数据库读出这个对象,你需要更改这个对象的属性
然而,你把这个对象的标识符都改了。。请问,怎么行。。