0

TaskCategory.hbm.xml

<hibernate-mapping>
        <class name="TaskCategory" table="TASK_CATEGORY" select-before-update="true">
            <id name="taskCategoryId" type="integer">
                <column name="TASK_CATEGORY_ID" />
                <generator class="identity" />
            </id>
            <property name="taskCategory" type="string">
                <column name="TASK_CATEGORY" length="512" not-null="true" />
            </property>
            <property name="taskCategoryGroup" type="string">
                <column name="TASK_CATEGORY_GROUP" length="32" not-null="true" />
            </property>
            <property name="description" type="string">
                <column name="DESCRIPTION" length="255" />
            </property>

            <set name="jurisdictions" inverse="true" table="task_category_jurisdiction">
                <key>
                    <column name="task_category_id" not-null="true" />
                </key>
                <many-to-many entity-name="com.sterling.ag.model.Jurisdiction">
                    <column name="jurisdiction_ID" not-null="true" />
                </many-to-many>
            </set>
        </class>
    </hibernate-mapping>

Jurisdiction.hbm.xml

<hibernate-mapping default-access="field">
<class name="Jurisdiction" table="Jurisdiction">
    <id name="jurisdictionId" type="int">
        <column name="Jurisdiction_ID" />
        <generator class="identity" />
    </id>
    <many-to-one name="jurisdictionType" class="JurisdictionType" fetch="select">
        <column name="Jurisdiction_Type_ID" not-null="true" />
    </many-to-one>

     <one-to-one name="flattenedJurisdiction" class="FlattenedJurisdiction" />

    <set name="taskCategories" table="task_category_jurisdiction" fetch="select">
        <key>
            <column name="jurisdiction_id" not-null="true" />
        </key>
        <many-to-many entity-name="TaskCategory">
            <column name="task_category_id" not-null="true" />
        </many-to-many>
    </set>      
</class>

I want to achieve something like this:

 whereClause.append(" and a.jurisdiction_id not in (select distinct   (j.jurisdiction_id) from " +
                        "task_category_jurisdiction j)" );

There is another Hibernate file for "a" which contains jurisdiction. And where clause is a StringBuffer.

I have tried this:

DetachedCriteria dc1 = DetachedCriteria.forClass(TaskCategory.class);
dc1.setProjection(Projections.distinct(Projections.property("jurisdictions")));
criteriaQuery.add(Restrictions.not(Subqueries.in("a.jurisdiction", dc1)));
SJuan76
  • 24,532
  • 6
  • 47
  • 87
avinash chavan
  • 729
  • 2
  • 11
  • 27
  • @SJuan I tried this: DetachedCriteria dc1 = DetachedCriteria.forClass(TaskCategory.class); dc1.setProjection(Projections.distinct(Projections.property("jurisdictions"))); criteriaQuery.add(Restrictions.not(Subqueries.in("a.jurisdiction", dc1))); I am not sure about this! – avinash chavan Dec 18 '12 at 11:50
  • log the output query and see what you're getting. You can log to console. Once you do that, you can either try solving it yourself or paste it here for everyone to see what is wrong. – Mukus Dec 18 '12 at 12:12

0 Answers0