I have essentially the following tables:
Person (id, name, ssn)
Customer (id, account_start_date)
Order(id, customer_id, item, order_date)
My hibernate is basically configured as follows:
Code:
<hibernate-mapping package="my.pkg">
<class name="Person" table="person">
<id name="id" type="long" />
<property name="name" type="string" />
<property name="ssn" type="string" />
<joined-subclass name="Customer" table="customer" >
<key column="id" />
<property name="account_start_date" type="timestamp" />
<set name="orders" table="order" cascade="delete" order-by="order_date desc" >
<key column="customer_id" />
<one-to-many class="Order" />
</set>
</joined-subclass>
</class>
<class name="Order" table="order">
<id name="id" type="long" />
<property name="curstomer_id" type="long" />
<property name="item" type="string" />
<property name="order_date" type="timestamp" />
</class>
Loading a set of orders every time I get a customer from the database and passing that data around is negatively impacting my performance. I only ever need the most recent order for each customer to be loaded with that customer object. I do need to get all orders at other times, but when dealing with a customer, I only ever need the latest order. Naturally, I can't use a one-to-one mapping since it's not one-to-one. I can't do a join to the joined_subclass. I tried messing with subselects and formulas, but nothing seems to work. How can I configure my XML to load just the latest order instead of the entire set?
Thanks.