Sunday, 22 November 2009

InvalidDataAccessApiUsageException with Spring and NHibernate

If you get a Spring.Dao.InvalidDataAccessApiUsageException with the following message…

“Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition”

…check that you have added the [Transaction(ReadOnly = false)] attribute to the appropriate data access method (assuming it’s a method that modifies data). Alternatively, if the attribute is already present, check that ReadOnly is not set to true.