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: Force NH not to override changes
PostPosted: Sat Feb 23, 2008 3:24 pm 
Newbie

Joined: Sat Feb 23, 2008 2:51 pm
Posts: 10
Hi
I have a difficult question.

Let's assume I have a model:

Order {Id, Price, Weight, Color }

and I get a list of Orders where Order.Price == 10. Then
in one of the objects from the returned list I change A1.Weight = 100,
(let's say that one instance is named A1).

Then in the same session I get a list of Orders where Order.Color = Red
and the returned list contains A1 ** (Instance A1 had Color == Red). But this instance will have restored Weight to the previous value. Changes made by me will be overridden.

** the object A1 will be loaded at first and second time will be the same instance, because NHibernate uses IdentityMap.

And my question: is there possibility to force NHibernate not to override changes made by me on loaded objects during session
when reloading object from DB? I want NH to recognize that I have modified some objects and it should leave them alone (till flush).
And I don't want to use transactions!

Andrew

Hibernate version: 1.2


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 24, 2008 8:59 am 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
Hi,

With Flush() you send the object to the DB.
With Evict() you clean the Session-Cache

You need to get used to using Transactions, because in NH2.0 are mandatory, and believe me is a good practice.

Try with this methods and let me know if the problem remains

_________________
Dario Quintana


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 24, 2008 12:53 pm 
Newbie

Joined: Sat Feb 23, 2008 2:51 pm
Posts: 10
Hi
Well, you didn't quite answer my question ;) Evict is no option here, I don't need it.
I also can't do flush, because I need "Cancel" option in my "use case".

I know that "transactions are good", but they shouldn't be long. And that's the problem. I have one session per "use case", but entering new data may last for long (in "back office" for instance), even an hour!

Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 24, 2008 4:46 pm 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
Hi Andrew, I can't reproduce it at NH of the trunk. I do this:

Code:
IList<Order> list = s.CreateQuery("from Order o where o.Price = 10").List<Order>();

Order A1 = list[0];

A1.Weight = 100;

IList<Order> list2 = s.CreateQuery("from Order o where o.Color = 'red'").List<Order>();

Assert.AreEqual(100,A1.Weight);


After the 2nd query, A1.Weight remains with the same value. All in the same session.

Those because NHibernate get the same instance from the first level cache. NH1.2.1 must have the same behavior.

_________________
Dario Quintana


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 25, 2008 11:16 am 
Newbie

Joined: Sat Feb 23, 2008 2:51 pm
Posts: 10
I have written similar code in unit test and it works :-\ Now it's seems that the problem lies in Data Binding or even something else.

I hope we'll manage it ;)

Thanks for help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 4:20 am 
Newbie

Joined: Sat Feb 23, 2008 2:51 pm
Posts: 10
Finally I know where the problem lied. We had on purpose turn AutoFlush off. But queries don't work properly then :(

As far as I know there's no way to force NH you query db as well as internal objects (without flush).

Andrew


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.