Given a Device, I want to include the device_type_name property (from a foreign table) in the Device object: I do NOT want a reference to the entire DEVICE_TYPE row or an entire Device_type object (composition).
The relational DB tables are (pseudo code to keep it short)
Code:
DEVICE
device_id bigint
device_name varchar
device_type_fk bigint references DEVICE_TYPE
...
and
DEVICE_TYPE
device_type_id bigint
device_type_name varchar
...
For context, lets asssume that a device_type object is a hugely unwieldy thing that I'd rather not have in this particular application.
The Java Object I do want looks like:
Code:
class Device
long device_id
String deviceName
String deviceTypeName
Note that this class has a device_type_name, NOT a device_type_fk or device_type object.
A typical SQL select to achive what I want would be:
Code:
select device_id, device_name, device_type_name from DEVICE d, DEVICE_TYPE dt
where d.device_type_fk = dt.device_type_id
HOW DO I CREATE A MAPPING TO EXPRESS THE Device CLASS, GIVEN THE DEVICE AND DEVICE_TYPE TABLES?
Code:
<hibernate-mapping>
<class name="Device" table="DEVICE">
<id name="deviceID" column="device_id" type="long" />
<property name="deviceName" column="device_name" type="string"/>
<!-- THIS IS CERTAINLY WRONG: -->
<property name="deviceTypeName" column="?????device_type.device_type_name" type="string"/>
</class>
</hibernate-mapping>