In a loop (let say 1000 iterations)
1) if I make just one query (session.CreateQuery()), it's fast
2) if I make just an insert (session.Save()), it's fast
but if I do both in my loop, hibernate is very very slow.
This is true with any database but it doesn't occur with other ORM or with a native ADO.NET code.
It seems the method session.Evict() fix the issue.
Dos anyone have an explanation or advices?
Thanks in advance.
Example:
Code:
for(int i=0; i<1000; i++)
{
session.CreateQuery("from Test where name=?")
.SetString(0, "hello")
.UniqueResult();
MyObj obj = new MyObj();
session.SaveOrUpdate(obj);
// This makes execution fast but why?
// How can I avoid making this call?
session.Evict(obj);
}
Please notice this occurs event with 10 iterations, and this does not occur if I do 2 loops.
Exemple of fast code running without problem:
Code:
for(int i=0; i<1000; i++)
{
session.CreateQuery("from Test where name=?")
.SetString(0, "hello")
.UniqueResult();
}
for(int i=0; i<1000; i++)
{
MyObj obj = new MyObj();
session.SaveOrUpdate(obj);
}