views:

22

answers:

1

Hi guys,

So I was wondering whether it is best to update multiple rows in a database using an hql query or calling nhibernates save after modifying each object.. I know that the answer is the HQL query but please give me adequate reasons for the same. but there are disadvantages of using an HQL query right like my API has a hard dependency on the model if any change in the property name i hv to explicitly remember the existence of this query.

So do the pros outway the cons if yes after please quantify.

Thanks. Awaiting your answers.

A: 

If you declare your HQL update statement as a named query, NHibernate will validate it when it builds the session factory and will throw if there is any error. So if you ever change a property name and forget to change the HQL it will throw when your application starts up (i.e. fail fast), so that makes it quite safe.

Loading and saving each object individually is a pretty big performance hit IMO, I always try to let the database do its job whenever possible.

Mauricio Scheffer