I don't understand why you would need to set the id on an insert or update. Would these not be generated? Also you typically do not write insert or update queries you just modify the entity and when the transaction is committed hibernate will generate the appropriate update or insert query.