-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Session Refresh
PostPosted: Wed Oct 12, 2005 3:22 pm 
Newbie

Joined: Mon May 30, 2005 11:20 pm
Posts: 9
Location: Brasil
The method refresh is not working in the version 1.0. In the version that I was using 0.7, it was working properly.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 9:40 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Can you give more details? The code you are executing, ...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject: The example
PostPosted: Mon Oct 17, 2005 3:50 pm 
Newbie

Joined: Mon May 30, 2005 11:20 pm
Posts: 9
Location: Brasil
If I am not wrong, the method ISession.Refresh need to "refresh" (reload or load) an object from the database that the Ids matches with the defined in the object passed by argument. So when I try, for example:


Code:
public class TestA{
    private int id;
    private string someData;

    public int Id {
        get { return id; }
        set { id = value; }
    }

    public int Data {
        get { return someData; }
        set { someData = value; }
    }

    public TestA()
    {}
}

...
void someMethod(ISession session)
{
    TestA a = new TestA();

    a.Id = 2; // using some object with Id 2 in the database

    session.Refresh(a);

    /* I expect for the data from the database of the object
        that have the Id = 2 to be loaded, but it doens't
    */
    Console.WriteLine("Id: {0} Data: {1}", a.Id, a.Data);

    /* And if I call the method ISession.Load for example
        I will have an error, because it says that the object already
        was loaded.
    */
    session.Load(a, a.Id); // or a = (TestA) session.Load(typeof(TestA), 2);
}
...



I have used the same code before in version 0.7 and was working. This situation can be reversed when I use ISession.Clear and ISession.Load, but in this way I lost all the objects that already was loaded and
other thing, when I use composite keys I need this method because the method ISession.Load supports only one key value to loaded.


Top
 Profile  
 
 Post subject: Details
PostPosted: Thu Oct 20, 2005 6:56 pm 
Newbie

Joined: Mon May 30, 2005 11:20 pm
Posts: 9
Location: Brasil
KPixel wrote:
Can you give more details? The code you are executing, ...


Hey, what about this situation? Am I wrong or the NHIbernate has a bug? :?:


Top
 Profile  
 
 Post subject: Re: The example
PostPosted: Thu Oct 20, 2005 9:55 pm 
Newbie

Joined: Thu Oct 20, 2005 5:17 pm
Posts: 19
Squall_Leonhartt wrote:
If I am not wrong, the method ISession.Refresh need to "refresh" (reload or load) an object from the database that the Ids matches with the defined in the object passed by argument.


The Refresh method is to refresh ("reload", yes, but not "load") an object that is already under NHibernate's control with any updates that may have occurred at the database level, such as with a trigger. I don't believe that it is meant to be used in the way you describe. You are using it against an object that NHibernate knows nothing about. It was probably just an accident that it ever worked in a previous version.


Top
 Profile  
 
 Post subject: Re: The example
PostPosted: Tue Oct 25, 2005 10:22 pm 
Newbie

Joined: Mon May 30, 2005 11:20 pm
Posts: 9
Location: Brasil
Jeff Bigler wrote:
Squall_Leonhartt wrote:
If I am not wrong, the method ISession.Refresh need to "refresh" (reload or load) an object from the database that the Ids matches with the defined in the object passed by argument.


The Refresh method is to refresh ("reload", yes, but not "load") an object that is already under NHibernate's control with any updates that may have occurred at the database level, such as with a trigger. I don't believe that it is meant to be used in the way you describe. You are using it against an object that NHibernate knows nothing about. It was probably just an accident that it ever worked in a previous version.


Ok, but I could be wrong, like I said before. This description was what cause the doubt.

Quote:
ISession.Refresh - Overloaded. Re-read the state of the given instance from the underlying database, with the given LockMode.


It says that the method re-read the object instance from the database, so I thought that re-read means re-load.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.