anthony wrote:
Quote:
Map of date -> price.
do you know tha <map/> tag? it allows lazy loading, for example if the collection is lazy, calling myObject.getPrices().get(myDate); will only load the wanted price.
Advice: write business methods on your pojo: myObject.getPrice(myDate) is great ;)
Hello Anthony,
I tried it, but it loaded the whole <map> collection in one go. Should it work in Hibernate 2.x?
This is my mapping:
Code:
<class name='Index' table='SE_INDEX' mutable='false'>
<id name='id' column='index_id' access='field'>
<generator class='assigned'/>
</id>
<property name="name" column="name" access="field"/>
<property name="tsCurrency" column="ccy" access="field"/>
<map name="timeSeries" table="se_index_ts" lazy="true" access="property">
<key column="index_id"/>
<index column="adate" type="date"/>
<element type="double" column="value"/>
</map>
</class>
When I try to access index.getTimeSeries.get(someDate) the following query is generated:
Code:
select timeseries0_.index_id as index_id__, timeseries0_.value as value__, timeseries0_.adate as adate__ from pms.se_index_ts timeseries0_ where timeseries0_.index_id=?
When I access other parts of the Map afterwards, no more queries are being generated. So it looks like the whole map is loaded at once in spite of laze="true" setting.
Is there any setting I have to make to influence this?
Also I cannot use a filter query in this case. I tried the following:
Code:
List result = session().createFilter(idx.getTimeSeries(), "where adate in (?,?)").setDate(0, from).setDate(1, to).list();
I know adate is not correct. I should use a property of the Collection, but in this case I need to filter by index. It doesn't seem to be possible :(.
Must I map the collection as a full blown entity using <one-to-many>? Can I use <map> together with <one-to-many>; the documentation shows only <set> and <bag> examples with <one-to-many>.
Thanks,
Peter