So I have an update on figuring this out.  I got most of it working, there
was a bug in XDoclet with subclass generation (classes outside the package of
the base class were not being found) and with 34 subclasses I hadn't realized
there was an issue.  XDoclet CVS has a resolution to this.

Now that the mapping is generated correctly, I've been able to load sample
data and try it out.  Given the pattern of the sample code below, by chance I
have 34 subclasses.  One of the subclasses is "Folder", which is simply a
container class... it is the only subclass that will have a Collection of the
base type.  I've updated the pseudocode below to show this.

So I try out this code, and I get a query for instantiating the collection
subclasses from the base class is almost 24KB in size.  MySQL fails with an
error stating "Too many tables. MySQL can only use 31 tables in a join".

So I set hibernate.use_outer_join to false.  That reduced the size of the
query down to just under 10K, but the problem with exceeding the maximum
number of tables still exists.

I see what is going on, the Hibernate has no way to know which subclass table
has the foreign key of the base class table, so it has to search all the
subclass tables.  I didn't put this together until things were running.  But
what I'm needing is for the base class table to have a table discriminator in
it such that all tables are not required to be searched for the foreign key
and instead are iterated according to what tables actually need to be
searched.

Unless I am looking at the problem wrong and someone can steer me
differently, I'm starting to consider whether I can generate a patch that
supports this.  If I were to consider generating a patch, where might I want
to start looking?  Is most of what I need to look at in Loader.java or are
there some more areas that I should keep my eye on?  I'm still not up to
speed with things yet in the code, but it seems like returning multiple
collections (one for each table) would allow the higher level code to be left
untouched since it just iterates over the array of returned collections at
some level.

Thanks for your consideration of all this!!

-b

    /**
     * base class everything inherits from
     * @hibernate.class
     */
    public class Base {
        private Long id;
        private Long parentFolder;

        /**
         * @hibernate.id column="parentFolder" unsaved-value="null"
generator-class="native"
         */
        public Long getParentFolder() { return parentFolder; }
        public void setParentFolder(Long parentFolder) { this.parentFolder =
parentFolder; }

        /**
         * @hibernate.id column="id" unsaved-value="null"
generator-class="native"
         */
        public Long getId() { return id; }
        public void setId(Long id) { this.id = id; }
    }

    /**
     * not really relevant, just a container for data
     * @hibernate.joined-subclass
     * @hibernate.joined-subclass-key column="subKey"
     */
    public class A extends Base {
        //...
    }

    /**
     * not really relevant, just a container for data
     * @hibernate.joined-subclass
     * @hibernate.joined-subclass-key column="subKey"
     */
    public class B extends Base {
        //...
    }

    // add a bunch more subclasses of Base here

    /**
     * the container class
     * @hibernate.joined-subclass
     * @hibernate.joined-subclass-key column="subKey"
     */
    public class Folder extends Base {
        private java.util.Collection items;

        public static Folder getRoot() {
            return (Folder) sess.find("from Folder as f where f.parentFolder
is null")
                      .iterator().next();
        }

        /**
         * @hibernate.set role="Items" lazy="true"
         * @hibernate.collection-one-to-many class="Base"
         */
        public java.util.Collection getItems() {
            return this.items;
        }

        public void setItems(java.util.Collection items) {
            this.items = items;
        }
    }

    public static void main(String[] args) {
        // set up session
        // ...
        Folder root = Folder.getRoot();
        Collection items = folder.getItems();
        for (Iterator it = items.iterator(); it.hasNext();) {
            Object o = it.next();
            if (o instanceof A) {
                //...
            } else if (o instanceof B) {
                //...                    
            } else if (...) {
                // ... deal with all the other subclasses
            }
        }
    }


-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to