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>
我想实现这样的目标:
whereClause.append(" and a.jurisdiction_id not in (select distinct (j.jurisdiction_id) from " +
"task_category_jurisdiction j)" );
还有另一个包含管辖权的“a”的Hibernate文件。 where子句是StringBuffer
。
我试过这个:
DetachedCriteria dc1 = DetachedCriteria.forClass(TaskCategory.class);
dc1.setProjection(Projections.distinct(Projections.property("jurisdictions")));
criteriaQuery.add(Restrictions.not(Subqueries.in("a.jurisdiction", dc1)));