Hibernate  � saveOrUpdate()  error  ! I had resolved this problem now!

AbstractADO.java
protected void saveOrUpdate(Object obj) {
try {
startOperation();
session.saveOrUpdate(obj);
// session.flush();
tx.commit();
} catch (HibernateException e) {
handleException(e);
} finally {
HibernateFactory.close(session);
ChinatCityDAO.java
public boolean insert(ChinaCity city){
System.out.println("ID : " city.getCityId() " City : "+city.getCityName());
saveOrUpdate(city);
return true;
++++++++++++++++++++
I want to to finish a insert Action with the ChinatCityDAO.java extends AbstractADO.java
1. the first time I submit a form. the console print out:
ID : null City : shanghai
Hibernate: insert into china_city (CityName, CityId) values (?, ?)
and a record in mysql database:
mysql>select * from china_city;
--------------------------------------------------------------------+
| CityId | CityName |
--------------------------------------------------------------+
| 402881e70f8a5bc9010f8a5bcf720001 | shanghai |
--------------------------------------------------------------------+
successful !!
2 then back to record a new info again, the console print out:
ID : 402881e70f8a5bc9010f8a5bcf720001 City : shanghai2
Hibernate: update china_city set CityName=? where CityId=?
ERROR! why not insert this time?but Update?
what shall i do?
setCityID(null) ; the run successful!
(A n unnative english man)
Message was edited by:
limo
Message was edited by:
limo

?

Similar Messages

Maybe you are looking for