Thanks a lot for your reply and patience.
Please excuse me, I try to make my requirements clearer.
I have 2 tables:
Code:
create table security (
security_id int /* for example 123456 */
, name varchar /* for example JBoss Corp. */
, constraint PK primary key (security_id)
)
/* this is a really huge table */
create table price (
security_id int /* for example 123456 */
, date date /* for example 1.jan.2005 */
, price float /* for example 1.23 */
, constraint PK primary key (security_id, date)
, constraint FK foreign key (security_id) references security(security_id)
)
I have two classes :
Code:
class Security {
private int security_id; // plus getter and setter
private String name; // plus getter and setter
private SortedMap prices;// mapped to the table prices.
// we want this map, in order to avoid the business logic programmers
// to deal with queries, they should just nuvigate through the map
public SecurityPrice getPrice(date) {
return (SecurityPrice) prices.get(date);
}
}
class SecurityPrice { // the existence of this class is not mandatory
private date Date; // plus getter and setter
private Security security; // plus getter and setter
private price double; // plus getter and setter
}
When the method prices.get(date) is called, if the price for the given date is not in the cache, I would like to control which HQL is executed.
Let's say, for example, the HQL should select all the instances of securityPrice (I mean for all the securities) at given date, and load them in cache.
If later we call the method get(same_date) again, on another prices instance (belonging to another Security instance), I expect the price to be loaded from the cache.
1)As far I understand, <loader> looks as the simplest and most promising solution. But:
- How will look my <map> tag (mapping the SortedMap "prices" to the table "price") ?
- How do I pass the date to the named query ?
2) CustomType : make Security mapped by a custom type : I do not see this solution. Do you mean map Security using a UserType ?
3) Collection Filter : I do not think this fits into, given that the "prices" map does not necessarily contains all the elements I want to prefetch. Right ?
4) Same as 3) right ?
5) Custom event listener : interesting.
- Am I allowed to issue an HQL query from within the LoadEventListener, or would it cause a kind of broken query nesting ?
- When I am notified by a LoadEvent, can I influence the decision of Hibernate to use a given HQL query ?
In clear, what actions am I allowed to take when processing the event ?
6) UserCollectionType : if this allows me to map any arbitrary collection (such as my own implementation of SortedMap), I like very much.
I have found UserCollectionType and PersistentCollection in the Javadoc, but it is not clear for an outsider like me to understand how to implement PersistentCollection.