Hibernate version: 3.0.5
Assume the following tables:
Code:
Foo (
id int not null primary key,
name varchar not null
)
Bar (
id int not null primary key,
foo_id int not null,
status_date date not null,
modified_date date not null
)
And the following classes:
Code:
class Foo {
int id;
String name;
Set<Bar> bars;
Bar bar;
}
class Bar {
int id;
Foo foo;
Date statusDate;
Date modifiedDate;
}
I want to map a particular Bar object to the Bar property of Foo based on an "order by" of the status and modified date columns. I understand that I can order the Set of Bar objects using order-by in the mapping. But I can't think of how to map the property.
And I need it mapped as a property for later queries for Foo that are based on properties of the most recent Bar and also for ordering the results of queries for Foo by the properties of the most recent Bar.
(Please note, these classes are simplified versions of the actual classes, both have many more properties)
I was thinking maybe I could use a <property> with a nested <formula> for the Bar, but I don't think I can return presisent entity references in formulas as I seem to have read they are pure SQL only.
Any ideas?
Thanks in advance,
Patrick