Hibernate executeupdate not updating
Hi, I was wondering if Query.execute Update() always return the number of deleted entities, or of this may depend on the database I'm using?The code above always return 0 (when testing with hsqldb), but all the entities that matches the query are deleted.I can get this working by doing an explicit flush: get Session().flush(); query.execute Update(); This happens only in Postgres and it appears like it has to do with the id generation mechanism.In SQLServer, Hibernate has to do an insert to get the id.In the case that doesn't work you are using a native SQL query, not Session.save(). AUTO should detect that an automatic flush is needed but the documentation about when an automatic flush happens is quite vague and only mentions Query.list().In any case, the only way to make the 'b' object to be inserted is to flush the session if that is an automatic or manual flush doesn't matter.
If you are facing a scenario where you need to update data on database then get it for further processing either you update it locally on your objects which will be residing in the persistence context ( in that case will make much more sence to do create Or Update instead of your query), or separate the two steps in 2 transactions You are performing the same query again, but you never committed the first transacation, hence the changes you made were never persisted.Its loads the roles fine, and save Or Update works fine for other objects, im not sure why it doesn't for this particular class. Thanks for the response, yes I thought that might be the problem and I called flush with no success.