I am having a difficult time finding other posts related to my current issue. So I was hoping someone can point me in the right direction.
I have four tables instance with a properties table called instance_property and association with a properties table called association_property. They each have there own mapping files which I will list below.
In the code, Association extends Instance.
So the problem I am having is everytime I query for Instance i.e. HQL - from instance i where type=:type.
This will create two queries "select i.* from instance i where i.type=:type" and "select i.* from association i where i.type=:type". I do not want both tables to be queried on. I Only want to query on the specific class I specify.. no subclasses.
Since Instance, Association, InstanceProperty, and AssociationProperty have there own mapping files and they both have there own tables (therefore no discriminators), how can I only have it query on Instance?
And querying on Association is fine since it does not have subclasses and it only executes one query.
Does anyone no how to do this using HQL? or do I need to use Criterias? or something else?
Hibernate version:
3.1.3
Mapping documents:
<!-- Instance -->
<class name="Instance" table="instance">
<cache usage="read-write" />
<id name="id" column="id" type="java.lang.Long">
<generator class="assigned" />
</id>
<version name="version" column="version" type="long" />
<map name="propertiez" table="instance_to_property">
<cache usage="read-write" />
<key column="instance_id" />
<index column="name" type="string" />
<many-to-many class="InstanceProperty"
column="instance_property_id" fetch="join" />
</map>
</class>
<class name="InstanceProperty"
table="instance_property">
<cache usage="read-write" />
<id name="id" column="id" type="long">
<generator class="native" />
</id>
<version name="version" column="version" type="long" />
<property name="name" column="name" type="string"
not-null="true" />
<property name="key" column="is_key" type="boolean"
not-null="true" />
<property name="value" column name="value" type="string"/>
</property>
</class>
<!-- Association -->
<class name="Association" table="association">
<cache usage="read-write" />
<id name="id" column="id" type="java.lang.Long">
<generator class="assigned" />
</id>
<version name="version" column="version" type="long" />
<map name="propertiez" table="association_to_property">
<cache usage="read-write" />
<key column="association_id" />
<index column="name" type="string" />
<many-to-many class="AssociationProperty"
column="association_property_id" fetch="join" />
</map>
<property name="referenceId1" column="referenceId1"
type="java.lang.Long" />
<property name="referenceId2" column="referenceId2"
type="java.lang.Long" />
</class>
<class name="AssociationProperty"
table="association_property">
<cache usage="read-write" />
<id name="id" column="id" type="long">
<generator class="native" />
</id>
<version name="version" column="version" type="long" />
<property name="name" column="name" type="string"
not-null="true" />
<property name="key" column="is_key" type="boolean"
not-null="true" />
<property name="value" column name="value" type="string"/>
</property>
</class>
|