Yuunli,
You're correct, the key is indeed composite, but unfortunately, that's irrelevant. I want to be able to fetch a list of all the extra text rows attached to a Person (and other objects), which mans I want to fetch based on a part of the key - the ID. If the ID would have been the same as the person ID, I could have used <one-to-many ...> from the Person object to a List of ExtraInfo objects, but I'm using (and have to use) a different key (which is not the primary key of the Person object). Basically, when calling Person.getExtraTextInfos() the following SQL should be generated (simplified):
Code:
select * from extra_info where id = {person.extra_info_id}
While it's true the key is composite, it's irrelevant here, and this fetch would be very efficient, since it's using the primary-key prefix as a filtering criterion.
I've used this method with SQL (before Hibernate) many times.
Also, I'm not interested in HQL code to fetch these rows for a specific person (or extraInfoId value), I want to have this as a getter on the Person class. Fetching the rows using HQL is easy, but I need to have easy access to the information once I have a Person object in my hands.
Just for completeness, here's the (abbreviated) HBM for the extra info class:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping ...>
<hibernate-mapping>
<class name="com.mycompany.ExtraInfo" ...>
<composite-id name="extraInfoKey" class="com.mycompany.ExtraInfoKey">
<key-property name="id" column="id" />
<key-property name="indext" column="indext" />
</composite-id>
<property name="text" column="text" />
</class>
</hibernate-mapping>
Please advise.