3 Replies Latest reply on Aug 27, 2003 4:58 PM by Kayvan Mojarrad

    JBoss 3.2.1 - Why does remove() need to load any fields othe

    Kayvan Mojarrad Newbie

      Hi,

      I'm trying to figure out why a call to remove() on an entity loads all the fields including the relationships before performing the delete.

      I have a query that is configured with on-load strategy.
      Initial query is:
      select id from table where .....
      I then iterate over the proxies and call only remove() on each one.
      Jboss then executes a whole lot of SQL to load all the fields including the relationships.
      And then I see:
      delete from table where id=?

      As I understand it the primary key is always loaded in the entity irrespective of optimization settings and as this is all that is required to delete the row, why then do all the fields need to be loaded.

      I know that I have cascade-delete on some of the relationships and I could understand if the primary keys of those were loaded as they're needed for the cascade-delete but the rest of the fields and all fields of all the relationships seems to be a complete sap of resources and makes a batch delete one of the lengthiest operations on JBoss.

      Has anyone else noticed this or is there something terribly wrong with my config???

      Thanks,
      kv.

        • 1. Re: JBoss 3.2.1 - Why does remove() need to load any fields
          Kayvan Mojarrad Newbie

          Please people,

          Can someone take a look at JBoss debug tail while you call remove() on an entity and see what sql gets executed.

          If anyone knows a way to remove an entity without first loading all it's fields. Please let me know.

          I have now tried this in a configuration with an on-load strategy and an empty eager-load group.
          This tells JBoss to load nothing other than the primary key the first time a method on the entity is called in a transaction. But it seems as though remove() has it's own rules and loads all the fields irrespective of load-groups.

          Even some confirmation of this would be most appreciated.

          Thanks,
          kv.

          • 2. Re: JBoss 3.2.1 - Why does remove() need to load any fields
            Raja Master

            If u have relation fields, then i guess all those records would be loaded as the relationship has to be removed when u delete the associated entry.
            Other than that, all i can see is a sql that says
            Delete from where <primary keys>

            Whats the SQL that shows up when you turn the log level in the CMP classes to Debug?

            -Raj

            • 3. Re: JBoss 3.2.1 - Why does remove() need to load any fields
              Kayvan Mojarrad Newbie

              Hi Raj

              Thanks for this - it gives me some hope to see when you call remove() you get no fields loaded.
              I am now wondering if this has something to do with the fact that as well as my empty eager-load group, I have a lazy-load group and maybe this group is getting loaded on remove. But I'm sure I read in JBoss docs that a lazy-load group is loaded the first time a getter for an unloaded member of that group is called - which should exclude a call to remove(). I'll try commenting out the lazy-load group and see what happens.

              I get SQL something like this on the debug tail:
              select form table column, column, ... (all the fields) where pk=?
              select column, ... (all the fields) from related where related.foreignKey = pk
              this for all the relationships including ones that have no cascade-delete.

              But here's a thing - At first I also thought it'd be necessary to load the relationships when removing an entity but when I think about it I wonder about that.
              If I remove the one side of a one to many relationship then to cascade-delete the many side all that would required is to execute:
              delete from related where related.fk = pk

              If I'm removing the one side of a one to one then depending on wether its a 2 way relationship or not I can either execute the same query as above or:
              delete from related where related.pk = relatedKey

              So why do the relationships have to get loaded?

              kv.