-->
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: Need a way to query only for specific class types
PostPosted: Mon Feb 26, 2007 4:31 pm 
Newbie

Joined: Mon Feb 26, 2007 10:13 am
Posts: 1
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>


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.