I am trying to get a record updated from a database using QueryOver. My code initially creates an entity and stores it in the database, then the same record is updated in the database from the outside (from another program, manually or from the same program running on another machine), and when I call QueryOverfiltering by field, the request receives a record but without the latest changes.
This is my code:
//create the entity and save in database
MyEntity myEntity = CreateDummyEntity();
myEntity.Name = "new_name";
MyService.SaveEntity(myEntity);
// now the entity is updated externally changing the name property with the
// "modified_name" value (for example manually in TOAD, SQL Server,etc..)
//get the entity with QueryOver
var result = NhibernateHelper.Session
.QueryOver<MyEntity>()
.Where(param => param.Name == "modified_name")
.List<T>();
The previous statement receives a collection with only one record (good), BUT with the set name with the old value instead of "modified_name".
How can I fix this behavior? Does level 1 cache bother me? The same problem occurs when
CreateCriteria<T>();
NhibernateHelper - , , session.Save().
, , -, , .
SQL NHibernate, WHERE ( Nhibernate ), !!!!
UPDATE
SaveEntity session.Save: Commit
public virtual void Commit()
{
try
{
this.session.Flush();
this.transaction.Commit();
}
catch
{
this.transaction.Rollback();
throw;
}
finally
{
this.transaction = this.session.BeginTransaction();
}
}
SQL, NHibernate SaveEntity:
NHibernate: INSERT INTO MYCOMPANY.MYENTITY (NAME) VALUES (:p0);:p0 = 'new_name'.
SQL, NHibernate QueryOver:
NHibernate: SELECT this_.NAME as NAME26_0_
FROM MYCOMPANY.MYENTITY this_
WHERE this_.NAME = :p0;:p0 = 'modified_name' [Type: String (0)].
- .
.