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