Re: Finally which ORM tool?



Jon Skeet [C# MVP] wrote:
In pure ADO.NET you wouldn't have had an object tree which was meant
to represent the same state as the server, so the aliasing wouldn't
have been apparent.

Wouldn't you? What kind of things would you be passing back and forth between your n-tier application server and client in an pure ADO.NET implementation of the server? Did you pass datasets back and forth? I sure didn't.

So if you don't care about session lifetimes, just create a session
for each separate query - it's very easy to do.

What I do currently is the following (Pseudocode):

void Save(object objectToSave)
{
using (Session session = InsertORMHere.NewSession())
{
object fetched = session.GetByKey(objectToSave.Oid);
if (fetched == null)
{
session.Save(objectToSave);
}
else
{
fetched.CopyFrom(objectToSave);
session.Save(fetched);
}
}
}

Which is fine and with a bit of reflection (in the implementation of the CopyFrom method, to copy object properties across) this works (and avoids an insert where an update should have occurred because of the whole business with sessions)... but it is, none the less, a workaround.

I'm not sure if you're playing the devils advocate or if you're just generally hostile to change but it seems to me that what I'm suggesting is certainly an improvement over the existing frameworks which REQUIRE me to write the above workaround because they REQUIRE sessions, even though these are not required in order for these ORMs to do their work. The idea of a session is only required by a select portion of the people using these ORMs so it seems insane to impose it on the rest of the applications using these ORMs... It's like forcing every application to choose a TCP/IP port, even if they don't use TCP/IP - what's the point??? The only thing it achieves is to inconvenience developers using these frameworks.

Surely it would be possible to overload the Save/Load methods of the
persistence framework to either take a session parameter or not. Or
maybe have two PersistenceController classes - one which is implicitly
sessionless and another which is not.

Again, it would be very easy for you to do that yourself, just
creating the session when you need to.

Yes but why should I? Why the heck isn't it built into the frameworks and why do they cling needlessly to a dependence on sessions when the OPTION to use sessions would suffice.

I've done plenty of n-tier work, and it's *not* the opposite for n-
tier frameworks. I suspect it depends on what you really want the ORM
system to do for you, but I've never regarded the session handling as
a problem, especially as Hibernate/nHibernate provide the ability to
"re-attach" an object from a previous session into a new one when you
want to.

I said sessions created a problem in n-tier (where they don't in desktop apps) and if you've done a lot of n-tier work then you must realize this is the case, since sessions in n-tier typically get created and destroyed on a per thread basis and threads get created/destroyed on a per request basis... requiring the workaround I described above in order to effect updates.

I wasn't aware of the re-attach behavior in nHibernate though... that sounds interesting and would at least reduce the amount of needless code I write to one line. I'll try to track down some info on this on the net (although one of my projects is using XPO and they don't have such a "feature"). Thanks for the tip.

Best Regards,

James Crosswell
Microforge.net LLC
http://www.microforge.net
.



Relevant Pages

  • Re: RWW Timing
    ... I understand that you want to monitor when and how ... > to an internal Windows XP or Terminal Server computer. ... SBS creates a connection to the internal client on port 3389 which is ... But it can not tell which one session from the RWW, ...
    (microsoft.public.windows.server.sbs)
  • Re: Restricting TS USers
    ... MCSE, CCEA, Microsoft MVP - Terminal Server ... Terminal Services and Microsoft Windows Server 2003 Service Pack ... the remote session does not end immediately. ...
    (microsoft.public.windows.terminal_services)
  • Re: ASP sessionstate
    ... :>: so it is a clientside issue. ... ASP doesn't know or care what browser it ... but then it is not a new session. ... :> How can a Response.Write write to the server screen? ...
    (microsoft.public.inetserver.asp.general)
  • Re: ASP sessionstate
    ... ASP doesn't know or care what browser it ... ticket number given when the first item is added to the cart. ... How can a Response.Write write to the server screen? ... :> delete the cart file and set the session ...
    (microsoft.public.inetserver.asp.general)
  • Re: Explanation of macros; Haskell macros
    ... > server and I got to dictate the form of the commands and arguments. ... it boiled down to (funcall command client-session args). ... Let's assume there is a type "Session" for sessions. ... You don't need the first constraint, ...
    (comp.lang.python)