Programming, technology, and CRM – from a Belgian programmer exiled to Missouri
  • rss
  • Home
  • Contact Me
  • Welcome

NHibernate does not read uncommitted data!

Nicolas Galler | June 5, 2007

This came as a bit of a shock for me being used to work directly with the database but it makes so much sense when you think about the unit of work pattern implemented by NHibernate/Hibernate.
When you work directly with the database, an update query is immediately sent, and a subsequent select query (within the same transaction) will return the updated data, even though the transaction has not committed yet. But with Hibernate, the query gets “cached” as a unit of work. A subsequent query to retrieve that particular item (by id) will hit the level 1 cache and return the updated item, but a criteria query may not find it, if you just updated the criteria being searched on.
Basically:

ITransaction tx = sess.BeginTransaction();
Account a = new Account();
a.AccountName = "what a cutie";
sess.Save(a);
// now an HQL query "from Account a where a.AccountName='what a cutie',
// will not return the new account!

This is very apparent if you use the profiler and look at the order of the queries… the insert query gets sent after the select one!
In order to get this to work you need to add a call to sess.Flush():


ITransaction tx = sess.BeginTransaction();
Account a = new Account();
a.AccountName = "what a cutie";
sess.Save(a);
sess.Flush();
// now an HQL query "from Account a where a.AccountName='what a cutie',
// will return the new account

Had me pulling my hair for a moment, now I am smacking myself for not seeing the obvious. Too bad NHibernate does not flush automatically before submitting HQL queries. There might be an option for that.

Comments
No Comments »
Categories
Programming
Comments rss Comments rss
Trackback Trackback

On Resharper

Nicolas Galler | June 2, 2007

I have been using Resharper for about 3 weeks now. There are a lot of very very cool things there:

  • The refactoring methods are a must – I would hate to go back to the VS2005 refactoring now. A lot more flexibility, a lot faster, and a lot of things that are simply not possible with VS2005 (eg renaming namespaces)
  • Ability to do quick templates – they are like macros except easier to set up.
  • The automatic error notification. This might be the biggest productivity improvement – it is a lot better than VS at reporting errors at edit time.

That being said, there are still quite a few annoyances and I am still deciding whether it is worth putting up with them:

  • The VS keybindings are well, not there anymore. This makes it twice as hard to switch between machines that don’t have Resharper installed. I wish they had tried to keep them somewhat similar
  • My intellisense now seems to bug out once in a while. Usually restarting VS fixes it, sometimes I have to turn it off and back on. Sadly I am unable to get Resharper’s built-in intellisense to work reliably, which makes using the templates a bit more tedious.
  • It slows down startup, a bit. Happens mostly in the background so that’s not major
  • It creates a bunch of files: resharper, resharper.user, resharper folder… I wish they kept it in just one folder rather than polluting mine.

Oh well, still an awesome tool. Once the eval runs out I’ll probably give a try to Coderush. Then the fun part will be to try and get my boss to pay for it, hah!!

Comments
No Comments »
Categories
Programming
Comments rss Comments rss
Trackback Trackback

Categories

  • Experiments (4)
  • Interesting (1)
  • MSCRM (1)
  • Programming (60)
  • Rant (3)
  • Saleslogix (34)
  • Tricks (8)
  • Uncategorized (24)

Post History

  • 2010
    • January (3)
    • March (1)
  • 2009
    • March (2)
    • April (1)
    • May (3)
    • June (3)
    • July (1)
    • September (3)
    • October (2)
    • December (5)
  • 2008
    • January (9)
    • February (4)
    • March (9)
    • April (1)
    • May (5)
    • June (8)
    • July (1)
    • August (2)
    • September (1)
    • November (1)
    • December (3)
  • 2007
    • January (3)
    • February (7)
    • March (1)
    • April (3)
    • May (6)
    • June (2)
    • July (1)
    • August (2)
    • September (5)
    • October (3)
    • November (5)
    • December (4)
  • 2006
    • January (2)
    • September (1)
    • November (3)
    • December (4)
  • 2005
    • April (1)

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox