Hello,
I'm a newbee to NHibernate and would like to get some advice on implementing transactions for my project. Here's what the code does :
1. I'm looping through a foreach statement to create my business objects (mapped in .hbm files)
2. After foreach statement all objects are persisted into the database with the following code
Code:
/// <summary>
/// Saves an object and its persistent children.
/// </summary>
public void Save<T>(T item)
{
using (ISession session = m_SessionFactory.OpenSession())
{
using (session.BeginTransaction())
{
session.SaveOrUpdate(item);
session.Transaction.Commit();
}
}
}
Than, within the foreach statement I should update some values in my database with and SQL query
Code:
IQuery query = session.CreateSQLQuery("UPDATE somethin'");
query.ExecuteUpdate();
The problem is that if the session.SaveOrUpdate(item); fails the values updated in foreach statement with the SQL query are not rolled back.
Any idea on architecture issue ?
Thanks in advance for your help.
Hibernate version:2.0.50727