some problems with ORM concept....what do you think?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bruce One

    #1

    some problems with ORM concept....what do you think?

    For all the ORM i have searched around, I have always found two big problems:

    1) To update or delete a set of records you must first bring it to memory.
    If you are inside a loop and have to do it n times, then you have to query
    this set n times as well. Would be nice if ORM could make it easier (in a
    strongly type manner) to call a dynamic query to directly update/delete
    records.

    2) I have noticed all ORM work with collection as thei return datatype of a
    query. Well, you cannot add, delete, replace, or reorder the elements in this
    collection...th is restrict a lot the way you can work, specially if you are
    iterating in a loop and have to make changes to the same table you are
    iterating...

    What are your opinions about it ?
  • Jimmy

    #2
    Re: some problems with ORM concept....what do you think?

    Sure you can do all of that with HQL in NHibernate.

    J.

    Bruce One wrote:
    For all the ORM i have searched around, I have always found two big problems:
    >
    1) To update or delete a set of records you must first bring it to memory.
    If you are inside a loop and have to do it n times, then you have to query
    this set n times as well. Would be nice if ORM could make it easier (in a
    strongly type manner) to call a dynamic query to directly update/delete
    records.
    >
    2) I have noticed all ORM work with collection as thei return datatype of a
    query. Well, you cannot add, delete, replace, or reorder the elements in this
    collection...th is restrict a lot the way you can work, specially if you are
    iterating in a loop and have to make changes to the same table you are
    iterating...
    >
    What are your opinions about it ?

    Comment

    • Bruce One

      #3
      Re: some problems with ORM concept....what do you think?

      I may have misexposed what I really meant.
      I meant all ORM do HAVE these 2 problems below...
      Hibernate (which I have already studied) works exaclty this ways, that is,
      it has to bring to memory all records it needs to update/delete, and, since
      it works with collections, you just cant update/delete any member of this
      collection in such a way the collection gets "lost"....

      "Jimmy" wrote:
      Sure you can do all of that with HQL in NHibernate.
      >
      J.
      >
      Bruce One wrote:
      For all the ORM i have searched around, I have always found two big problems:

      1) To update or delete a set of records you must first bring it to memory.
      If you are inside a loop and have to do it n times, then you have to query
      this set n times as well. Would be nice if ORM could make it easier (in a
      strongly type manner) to call a dynamic query to directly update/delete
      records.

      2) I have noticed all ORM work with collection as thei return datatype of a
      query. Well, you cannot add, delete, replace, or reorder the elements in this
      collection...th is restrict a lot the way you can work, specially if you are
      iterating in a loop and have to make changes to the same table you are
      iterating...

      What are your opinions about it ?
      >
      >

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: some problems with ORM concept....what do you think?

        Bruce One <raul@virtualso ftware.com.brwr ote:
        I may have misexposed what I really meant.
        I meant all ORM do HAVE these 2 problems below...
        Hibernate (which I have already studied) works exaclty this ways, that is,
        it has to bring to memory all records it needs to update/delete, and, since
        it works with collections, you just cant update/delete any member of this
        collection in such a way the collection gets "lost"....
        No, Hibernate (at least the Java version) does *not* have to fetch
        records in order to update/delete them.

        See

        -direct

        aka http://tinyurl.com/4kpug

        and scroll down to "DML-style operations".

        --
        Jon Skeet - <skeet@pobox.co m>
        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
        If replying to the group, please do not mail me too

        Comment

        • Bruce One

          #5
          Re: some problems with ORM concept....what do you think?

          Well the example you linked to me works exaclty the way I put there...look at
          a piece of the code presented in the page you forward to me...

          ............... ...
          ............... ..
          // TAKE A LOOK AT THE getNamedQuery method. IT RETURNS ALL RECORDS THAT WILL
          BE UPDATED....

          ScrollableResul ts customers = session.getName dQuery("GetCust omers")
          .scroll(ScrollM ode.FORWARD_ONL Y);
          while ( customers.next( ) ) {
          Customer customer = (Customer) customers.get(0 );
          customer.update Stuff(...);
          session.update( customer);
          }

          tx.commit();
          session.close() ;




          "Jon Skeet [C# MVP]" wrote:
          Bruce One <raul@virtualso ftware.com.brwr ote:
          I may have misexposed what I really meant.
          I meant all ORM do HAVE these 2 problems below...
          Hibernate (which I have already studied) works exaclty this ways, that is,
          it has to bring to memory all records it needs to update/delete, and, since
          it works with collections, you just cant update/delete any member of this
          collection in such a way the collection gets "lost"....
          >
          No, Hibernate (at least the Java version) does *not* have to fetch
          records in order to update/delete them.
          >
          See

          -direct
          >
          aka http://tinyurl.com/4kpug
          >
          and scroll down to "DML-style operations".
          >
          --
          Jon Skeet - <skeet@pobox.co m>
          http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
          If replying to the group, please do not mail me too
          >

          Comment

          • Jon Skeet [C# MVP]

            #6
            Re: some problems with ORM concept....what do you think?

            Bruce One <raul@virtualso ftware.com.brwr ote:
            Well the example you linked to me works exaclty the way I put there...look at
            a piece of the code presented in the page you forward to me...
            >
            ............... ..
            ............... .
            // TAKE A LOOK AT THE getNamedQuery method. IT RETURNS ALL RECORDS THAT WILL
            BE UPDATED....
            >
            ScrollableResul ts customers = session.getName dQuery("GetCust omers")
            .scroll(ScrollM ode.FORWARD_ONL Y);
            while ( customers.next( ) ) {
            Customer customer = (Customer) customers.get(0 );
            customer.update Stuff(...);
            session.update( customer);
            }
            >
            tx.commit();
            session.close() ;
            Please read my post more carefully. You didn't scroll down to the "DML-
            style operations" section as I suggested.

            --
            Jon Skeet - <skeet@pobox.co m>
            http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
            If replying to the group, please do not mail me too

            Comment

            • Frans Bouma [C# MVP]

              #7
              Re: some problems with ORM concept....what do you think?

              Bruce One wrote:
              For all the ORM i have searched around, I have always found two big
              problems:
              >
              1) To update or delete a set of records you must first bring it to
              memory. If you are inside a loop and have to do it n times, then you
              have to query this set n times as well. Would be nice if ORM could
              make it easier (in a strongly type manner) to call a dynamic query to
              directly update/delete records.
              Not all O/R mappers force that on you. Some, like LLBLGen Pro (which
              I'm the lead developer of), offer the ability to update/delete entities
              directly in the persistent storage.

              The reason why O/R mappers don't offer these query capabilities often
              is based on the fact that it would make their internal caches
              completely void.
              2) I have noticed all ORM work with collection as thei return
              datatype of a query. Well, you cannot add, delete, replace, or
              reorder the elements in this collection...th is restrict a lot the way
              you can work, specially if you are iterating in a loop and have to
              make changes to the same table you are iterating...
              I'm not sure what your question is, but I don't recognize this
              limitation in my work. Which 'ORM' frameworks are you talking about?

              Frans


              --
              ------------------------------------------------------------------------
              Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
              LLBLGen Pro website: http://www.llblgen.com
              My .NET blog: http://weblogs.asp.net/fbouma
              Microsoft MVP (C#)
              ------------------------------------------------------------------------

              Comment

              • Bruce One

                #8
                Re: some problems with ORM concept....what do you think?

                Frans,
                You mean you would pass a raw sql to your update/delete method? Or is it
                done using Dynamic Query? If so, how an Update command like below would be
                called in your BusinessLogic, in such a way you can use all Strongly-Typed
                fields?

                Update Customers
                Set CustomerName = "Bruce"
                ,CustomerAge = 30
                WHERE CustomerID = 30


                "Frans Bouma [C# MVP]" wrote:
                Bruce One wrote:
                >
                For all the ORM i have searched around, I have always found two big
                problems:

                1) To update or delete a set of records you must first bring it to
                memory. If you are inside a loop and have to do it n times, then you
                have to query this set n times as well. Would be nice if ORM could
                make it easier (in a strongly type manner) to call a dynamic query to
                directly update/delete records.
                >
                Not all O/R mappers force that on you. Some, like LLBLGen Pro (which
                I'm the lead developer of), offer the ability to update/delete entities
                directly in the persistent storage.
                >
                The reason why O/R mappers don't offer these query capabilities often
                is based on the fact that it would make their internal caches
                completely void.
                >
                2) I have noticed all ORM work with collection as thei return
                datatype of a query. Well, you cannot add, delete, replace, or
                reorder the elements in this collection...th is restrict a lot the way
                you can work, specially if you are iterating in a loop and have to
                make changes to the same table you are iterating...
                >
                I'm not sure what your question is, but I don't recognize this
                limitation in my work. Which 'ORM' frameworks are you talking about?
                >
                Frans
                >
                >
                --
                ------------------------------------------------------------------------
                Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
                LLBLGen Pro website: http://www.llblgen.com
                My .NET blog: http://weblogs.asp.net/fbouma
                Microsoft MVP (C#)
                ------------------------------------------------------------------------
                >

                Comment

                • Bruce One

                  #9
                  Re: some problems with ORM concept....what do you think?

                  Jon, I saw it. But you must agree this is not Dynamic Query, it does not deal
                  with strongly-typed fields, its just raw sql, as the code extracted from the
                  Hibernate page (below)...

                  String hqlUpdate = "update Customer c set c.name = :newName where c.name =
                  :oldName";


                  "Jon Skeet [C# MVP]" wrote:
                  Bruce One <raul@virtualso ftware.com.brwr ote:
                  Well the example you linked to me works exaclty the way I put there...look at
                  a piece of the code presented in the page you forward to me...

                  ............... ..
                  ............... .
                  // TAKE A LOOK AT THE getNamedQuery method. IT RETURNS ALL RECORDS THAT WILL
                  BE UPDATED....

                  ScrollableResul ts customers = session.getName dQuery("GetCust omers")
                  .scroll(ScrollM ode.FORWARD_ONL Y);
                  while ( customers.next( ) ) {
                  Customer customer = (Customer) customers.get(0 );
                  customer.update Stuff(...);
                  session.update( customer);
                  }

                  tx.commit();
                  session.close() ;
                  >
                  Please read my post more carefully. You didn't scroll down to the "DML-
                  style operations" section as I suggested.
                  >
                  --
                  Jon Skeet - <skeet@pobox.co m>
                  http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                  If replying to the group, please do not mail me too
                  >

                  Comment

                  • Jon Skeet [C# MVP]

                    #10
                    Re: some problems with ORM concept....what do you think?

                    Bruce One <raul@virtualso ftware.com.brwr ote:
                    Jon, I saw it. But you must agree this is not Dynamic Query, it does not deal
                    with strongly-typed fields, its just raw sql, as the code extracted from the
                    Hibernate page (below)...
                    >
                    String hqlUpdate = "update Customer c set c.name = :newName where c.name =
                    :oldName";
                    No, it's not just raw SQL. You can use the properties to perform a
                    path, eg

                    "delete Customer c where c.address.zipco de = ...."

                    What else would you want out of ORM when it comes to updating or
                    deleting?

                    --
                    Jon Skeet - <skeet@pobox.co m>
                    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                    If replying to the group, please do not mail me too

                    Comment

                    • Frans Bouma [C# MVP]

                      #11
                      Re: some problems with ORM concept....what do you think?

                      Bruce One wrote:
                      Frans,
                      You mean you would pass a raw sql to your update/delete method? Or is
                      it done using Dynamic Query? If so, how an Update command like below
                      would be called in your BusinessLogic, in such a way you can use all
                      Strongly-Typed fields?
                      >
                      Update Customers
                      Set CustomerName = "Bruce"
                      ,CustomerAge = 30
                      WHERE CustomerID = 30
                      This uses a dummy entity instance to contain the NEW values for the
                      fields you're going to set. This also means that I can use an
                      expression.

                      CustomerEntity customer = new CustomerEntity( );
                      customer.Custom erName = "Bruce";
                      customer.Custom erAge = 30;
                      using(DataAcces sAdapter adapter = new DataAccessAdapt er())
                      {
                      adapter.UpdateE ntitiesDirectly (customer,
                      new RelationPredica teBucket(
                      CustomerFields. CustomerID==30) );
                      }

                      I also could have increased your age with 10% :) ->

                      CustomerEntity customer = new CustomerEntity( );
                      customer.Custom erName = "Bruce";
                      customer.Custom erAge.Expressio nToApply = (
                      CustomerFields. CustomerAge +
                      (CustomerFields .CustomerAge * 0.01f));
                      using(DataAcces sAdapter adapter = new DataAccessAdapt er())
                      {
                      adapter.UpdateE ntitiesDirectly (customer,
                      new RelationPredica teBucket(
                      CustomerFields. CustomerID==30) );
                      }

                      All strongly-typed compile time checked code.

                      FB
                      >
                      >
                      "Frans Bouma [C# MVP]" wrote:
                      >
                      Bruce One wrote:
                      For all the ORM i have searched around, I have always found two
                      big problems:
                      >
                      1) To update or delete a set of records you must first bring it to
                      memory. If you are inside a loop and have to do it n times, then
                      you have to query this set n times as well. Would be nice if ORM
                      could make it easier (in a strongly type manner) to call a
                      dynamic query to directly update/delete records.
                      Not all O/R mappers force that on you. Some, like LLBLGen Pro
                      (which I'm the lead developer of), offer the ability to
                      update/delete entities directly in the persistent storage.

                      The reason why O/R mappers don't offer these query capabilities
                      often is based on the fact that it would make their internal caches
                      completely void.
                      2) I have noticed all ORM work with collection as thei return
                      datatype of a query. Well, you cannot add, delete, replace, or
                      reorder the elements in this collection...th is restrict a lot the
                      way you can work, specially if you are iterating in a loop and
                      have to make changes to the same table you are iterating...
                      I'm not sure what your question is, but I don't recognize this
                      limitation in my work. Which 'ORM' frameworks are you talking about?

                      --
                      ------------------------------------------------------------------------
                      Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
                      LLBLGen Pro website: http://www.llblgen.com
                      My .NET blog: http://weblogs.asp.net/fbouma
                      Microsoft MVP (C#)
                      ------------------------------------------------------------------------

                      Comment

                      • Bruce One

                        #12
                        Re: some problems with ORM concept....what do you think?

                        Well Jon,
                        Its not 100% dynamic either...since you have to know table field names, as
                        in "c.name", rather than strongly typed fields that you could access through
                        intellisense...

                        "Jon Skeet [C# MVP]" wrote:
                        Bruce One <raul@virtualso ftware.com.brwr ote:
                        Jon, I saw it. But you must agree this is not Dynamic Query, it does not deal
                        with strongly-typed fields, its just raw sql, as the code extracted from the
                        Hibernate page (below)...

                        String hqlUpdate = "update Customer c set c.name = :newName where c.name =
                        :oldName";
                        >
                        No, it's not just raw SQL. You can use the properties to perform a
                        path, eg
                        >
                        "delete Customer c where c.address.zipco de = ...."
                        >
                        What else would you want out of ORM when it comes to updating or
                        deleting?
                        >
                        --
                        Jon Skeet - <skeet@pobox.co m>
                        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                        If replying to the group, please do not mail me too
                        >

                        Comment

                        • Jon Skeet [C# MVP]

                          #13
                          Re: some problems with ORM concept....what do you think?

                          Bruce One <raul@virtualso ftware.com.brwr ote:
                          Its not 100% dynamic either...since you have to know table field names, as
                          in "c.name", rather than strongly typed fields that you could access through
                          intellisense...
                          That's the current state of ORM though - it's no different in the rest
                          of the querying etc.

                          It feels like you're desperately trying to find reasons not to use
                          ORM...

                          --
                          Jon Skeet - <skeet@pobox.co m>
                          http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                          If replying to the group, please do not mail me too

                          Comment

                          Working...