AnantLabs / codesmith

Automatically exported from code.google.com/p/codesmith
1 stars 0 forks source link

Can not refresh new data from databasee #405

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Update new data via NHibernate like change the value from 01/01/2010 to 
10/10/2010
2. Call get list method, all records returned
3. The newly data is not present, it still old value like 01/01/2010 :(

What is the expected output? What do you see instead?
10/10/2010

What version of the product are you using?
Newest version of NHibernate Template

Please provide any additional information below.

Original issue reported on code.google.com by huanh...@gmail.com on 14 Jun 2010 at 10:05

GoogleCodeExporter commented 9 years ago
Can you please provide a code sample that can recreate this? Are you calling a 
SubmitChanges (flush) after you make the initial changes to our entities?

Original comment by tdupont...@gmail.com on 14 Jun 2010 at 3:14

GoogleCodeExporter commented 9 years ago
What we do is ensure that each object we get has a mgr.Refresh() call to it.

For example:

public MyEntity GetEntity(long id) 
{
   IMyEntityManager mgr = new ManagerFactory().GetMyEntityManager();
   MyEntity obj = mgr.GetById(id);
   if(obj != null) {
     mgr.Refresh(obj);
   }
   return obj;
}

Hope this helps either the way you code against the NHibernate templates.

Original comment by wayne.ma...@gmail.com on 18 Nov 2010 at 3:17

GoogleCodeExporter commented 9 years ago
Hello,

Each Manager should be wrapped in an using block. Can you please see if the 
following code resolves this issue.

public MyEntity GetEntity(long id) 
{
   MyEntity obj = null;
   using(IMyEntityManager mgr = new ManagerFactory().GetMyEntityManager())
   {
      obj = mgr.GetById(id);
      if(obj != null) {
        mgr.Refresh(obj);
      }
   }
   return obj;
}

Original comment by bniemyjski on 23 Nov 2010 at 11:08