views:

321

answers:

1

In a test where I want to persist an object and then prove it was persisted by fetching it from the db (and not the session), I notice no difference between the following:

// save it
session.Clear()
// fetch it

or

// save it
session.Flush()
session.Evict(_instance)
// fetch it

The lazy programmer in me leans towards one line over two. Is there some reason I am missing to favor the two lines more?

Cheers,
Berryl

A: 

session.Clear actually cancels all pending saves/updates/etc.

If it doesn't, it's because you're using identity so the entity is persisted without flushing.

Diego Mijelshon
Berryl