Ok, For some reason my Unit tests were passing when I wasn't using hibernate to persist (even though they shouldn't have), I found my problem (I wasn't initializing the internal Set before trying to use it - doh!). So, this is now working, but I am experiencing another problem.

Here's my layout:
id - generated id
parentid - should be pulled when the set is created
name
description
subCategories - set of categories

I can add a category to the subCategories object and have it be persisted properly (ie - id and parentid are set properly). However when I pull the subcategory from the Set the parentid is not present.

So, here is what I'm doing in my unit test:
Category newCat = (Category)sess.load(Category.class, id);
Set subCats = newCat.getSubCategories();
Category subCat = (Category)subCats.iterator().next();

assertEquals("subcat", subCat.getName());
assertEquals("First Subcategory", subCat.getDescription());
System.out.println("My subcat id is :: " + subCat.getId());
System.out.println("My subcat parentid is :: " + subCat.getParentId());

The first two asserts work as expected. getId() returns the proper id for this subcategory. getParentId() returns null.

here's the definition from my mapping file:
        <property
            name="parentId"
            type="java.lang.Long"
            update="true"
            insert="true"
            column="parentid"
        />
        <set
            name="subCategories"
            table="category"
            lazy="false"
            inverse="false"
            cascade="all"
            sort="unsorted"
        >

              <key
                  column="parentid"
              />

              <one-to-many
                  class="com.tucsonunderground.Category"
              />
        </set>

What has me baffled though is the fact that the parentid is set in the database to the proper parent id.

Thanks for all the help and suggestions so far. I am really liking Hibernate!

-warner



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to