-->
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: How to improve performance with polymorphism
PostPosted: Tue Jan 12, 2010 1:22 am 
Newbie

Joined: Mon Jun 20, 2005 12:20 pm
Posts: 17
Hi, Here are my classes:

Code:
class Item {
  long id;
  Set<AbstractData> metaData;
}

abstract class AbstractData {
  long ownerItemID;
  long dataID;
}

class DateData extends AbstractData {
  Date value;
}

class NumberData extends AbstractData {
  double value;
}

class TextData extends AbstractData {
  String value;
}


I am using table per concrete class (union-subclass). Hibernate creates the following query to load metaData in Item class:

Quote:
select
data0_.owner_item_id as owner2_1_,
...
from
(select
owner_item_id,
...
from date_data
union
select
owner_item_id,
...
from number_data
union
select
owner_item_id,
...
from text_data
) data0_
where data0_.owner_item_id=100


It takes about 5000ms to get data. If I changed the query to

Quote:
select
data0_.owner_item_id as owner2_1_,
...
from
(select
owner_item_id,
...
from date_data
where owner_item_id=100
union
select
owner_item_id,
...
from number_data
where owner_item_id=100
union
select
owner_item_id,
...
from text_data
where owner_item_id=100
) data0_


It will takes 20ms to get the result data set, which is about 250 times faster in my case.

My question is how to make change so that Hibernate to create the faster query. Of course, I still want to use the polymorphism (instead of 3 separate sets in Item for metaData). Any suggestion will be appreciated.

-ZJ


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.