-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Can Criteria exclude a subclass?
PostPosted: Wed Aug 10, 2005 11:27 am 
Newbie

Joined: Thu Jun 02, 2005 11:20 am
Posts: 9
hi all,

i've got a few classes here; Category is the parent.
Code:
Category
> Content Type ( child of Category )
> NavigationCategory ( child of Category )

** Note that these currently are NOT mapped as subclasses in Hibernate.

these are stored in the following tables:

Code:
iwsc_category ( Category )
iwsc_content_type (ContentType)
iwsc_navigation ( NavigationCategory)



the iwsc_category table has a discriminator column, category_type, which is there for extensibility. content type and navigation do not use this column (ie. it's not mapped in hb).

annnyway, here's the meaningful parts of the .hbm.xml:

Code:
  <class name="Category" table="iwsc_category">

    <id name="id" type="long" unsaved-value="-1">
      <column name="category_id" not-null="true"/>
    </id>

    <many-to-one name="type" index="idx_iwsc_category_type_branch" column="type_id" foreign-key="fk1_iwsc_category_type_id" insert="false" update="false" class="CategoryType" not-null="true" />
      ...
  </class>

  <!-- this is NOT a HB subclass of Category -->
  <class name="NavigationCategory" table="iwsc_navigation">

    <id name="id" type="long" unsaved-value="-1">
      <column name="category_id" not-null="true"/>
    </id>

    <property name="name"           type="string" length="150" not-null="true"/>
    ...
   </class>

  ... ContentType is similar to NavigationCategory...



When I run this:

Code:
         
          Criteria hibernateCriteria =
            session.createCriteria(Category.class);                     
              .add(Restrictions.in("type",typeArray));


I get this error when I run the query:

Code:
Caused by: org.hibernate.QueryException: could not resolve property: type of:
com.foo.common.model.category.NavigationCategory
   at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
   at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
   at org.hibernate.persister.entity.BasicEntityPersister.toType(BasicEntityPersister.java:1094)


my question is, why is it even looking at NavigationCategory? While it is a subclass of Category in Java, it's not mapped that way in Hibernate. Not sure if this is a feature or a bug, but wondering if I (a) have to change my architecture to use type across the board or (b) there's a way to exclude the subclass in criteria-based queries.

i appreciate any help.

thanks and keep up the great work!

shanon.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.