update query is firing first then insert query
Hi,
i have a requirement where first i need to insert list of records in to data base then i need to fire an update query to update some column's value of inserted records. but the problem is first it is firing update query and then insert query. how can prevent firing an update query first. for me insert query should be first then update query. please suggest me. following is code snippet.
Code Java:
method(){
if(list != null && list.size() > 0){
for (EntityClass entityClass : list) {
this.getHibernateTemplate().merge(entityClass);
}
}
if(true){
methodUpdate(); //this method calls some updating logic. here i used native update sql query.
}
}
Thanks,
Salmon
Re: update query is firing first then insert query
If your using mysql
-set a primary key in the database
-using insert......on duplicate key update .....
see MySQL :: MySQL 5.0 Reference Manual :: 12.2.5.3 INSERT ... ON DUPLICATE KEY UPDATE Syntax for more info
I had the same problem and now it works fine for me
Kurt