My issue is, I have a bunch of code that seems to be just a bunch of select statements, and yet for some reason, hibernate is committing dirty data. I don't want it to commit the new article to the database yet (maybe not until the next postback...I am using ASP)
Hibernate version:1.2
Code between sessionFactory.openSession() and session.close():
session = factory.OpenSession();
Magazine magazine = session.Get(typeof(Magazine ), 1);
magazine.Articles.Add(new Article("testText"));
IQuery query = m_session.CreateSQLQuery("SELECT Count(*) as ItemCount FROM PublisherEmployees WHERE FK_PublisherId=" + magazine.Publisher.Id).AddScalar("ItemCount", NHibernateUtil.Int32);
int numArticles = (int)query.UniqueResult();
session.Flush();
session.Close();
The only time I every want to commit data is when I call the save function below. Which I do not call in the above code
void Save(object item, bool pointlessParameter)
{
ITransaction tx=null;
try
{
tx = m_session.BeginTransaction();
m_session.SaveOrUpdate(item);
tx.Commit();
}
catch (Exception ex)
{
if (tx!=null) tx.Rollback();
throw ex;
}
}
Full stack trace of any exception that occurs: No errors
Name and version of the database you are using: SQL Server 2005 Express
|