-->
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.  [ 5 posts ] 
Author Message
 Post subject: Object saved wihout calling ISesson.Save().
PostPosted: Thu May 25, 2006 6:35 pm 
Newbie

Joined: Mon Jan 23, 2006 11:44 pm
Posts: 15
Location: New Jersey, US
Hi,

I am working on one ASP.NET 2.0 page. Session per HttpRequest pattern is used with NHibernate 1.01. In the page_load method, I create a new object of a mapped class with:

Order o = new Order();

If the code after this line try to query database in the same NHibernate session with, for example,

CurrentSession.Find(...); //Load for a dropdownlist

The object o will be saved to database without calling ISesson.Save(o). This is strange and wrong because a user may open the page without actually submit.

Any thing I did wrong?

Thanks,

Hongze


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 7:09 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
What you describe in your post is actually impossible (how is a session supposed to know about your order and save it to the database if you don't call Save on it?), so the problem must be elsewhere. Show us some code and possibly logs where it happens.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 2:39 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
sergey wrote:
What you describe in your post is actually impossible (how is a session supposed to know about your order and save it to the database if you don't call Save on it?), so the problem must be elsewhere. Show us some code and possibly logs where it happens.


What if he assigns some persitent object to property of new order and this assoctiation is configured to cascade saves?

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 3:28 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
You might be making the mistake I made when I first started using NHibernate - calling Save makes the instance persistent and it will remain persistent for the duration of the session in which it was saved. Save does not explicitly save the data into the database - it will be held in memory until a flush occurs.

Using Load, Get, Find, or any other method that allows you to retrieve persistent instances from the database into memory which will be considered persistent for the duration of your session.

NHibernate's transparent persistence means that any changes made to persistent objects in memory will be saved in the database automatically for you unless you change your FlushMode from the default Auto setting - exactly when it actually flsuhes the information into the database is handled by NHibernate.

Executing queries will flush before returning results so that the data in the database matches the data in memory and the query will return up to date results.

The documentation covers all this, but the docs can be a bit of a headfull for a beginner.

If this isn't your problem then just ignore me!

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 6:50 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
gert wrote:
What if he assigns some persitent object to property of new order and this assoctiation is configured to cascade saves?

This is possible, but I assumed he hasn't got to cascades yet :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.