-->
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: Efficient query for inheritance
PostPosted: Tue Nov 21, 2006 10:42 am 
Newbie

Joined: Tue Dec 27, 2005 10:39 am
Posts: 9
Hi,

I have a problem with an inefficient query that involves
a collection of a generic type which has a lot of subtypes (mapped with <joined-subclass>).
Example :
I have a library which has a collection of medias. Media are implemented as books, movies,etc.

I am unable to retrieve a media of a library of a given type efficiently.
Hibernate use outer joins for each subtypes and when there are numerous
subtypes, the query is really slow.

Each concrete media like book is an entity mapped with a <joined-subclass>.

The problem is i am unable to retrieve efficiently a media of a given type for a library.

I tried the following HQL query:
Code:
" select lib.medias from Library lib join lib.medias media where lib.id="+libraryId+" and media.class="+mediaClass.getName();


But it only works when a discriminator is declared for the parent class
and subclasses are mapped using a
<subclass name="..." discriminator-value="book">
<join table="book">
<key column="media_id">
...
</join>
</subclass>
which is not my case (see below mapping files).

Do you know how to force hibernate not to perform a outer-join on
each subtypes when i am only interested in a given single subtype ?




Hibernate version: 3.0.5

Mapping documents:
Code:
<hibernate-mapping>
  <class table="media" name="javaeesamples.hibernate.model.Media">
    <id access="field" name="id" column="media_id">
      <generator class="increment"/>
    </id>
    <discriminator column="media_type"/>
    <property name="title" length="100" column="title" access="field" not-null="true"/>
    <property name="author" length="100" column="author" access="field" not-null="true"/>
    <property name="releaseDate" column="releasedate" access="field" not-null="true"/>
    <joined-subclass name="javaeesamples.hibernate.model.Album" table="album">
      <property name="tracksNum" column="tracksnum" access="field"/>
    </joined-subclass>
    <joined-subclass name="javaeesamples.hibernate.model.Book" table="book" >
      <property name="chapsNum" column="chapsnum" access="field"/>
    </joined-subclass>
  </class>
</hibernate-mapping>



Code:
<hibernate-mapping>
  <class table="library" name="javaeesamples.hibernate.model.Library">
    <id access="field" name="id" column="id">
      <generator class="increment"/>
    </id>
    <bag cascade="all" access="field" lazy="true" table="media" name="medias">
      <key column="libraryid"/>
      <one-to-many class="javaeesamples.hibernate.model.Media"/>
    </bag>
    <property name="owner" length="100" column="owner" access="field" not-null="true"/>
  </class>
</hibernate-mapping>




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.