My problem is rather unique. I’m trying to map a single object to multiple tables, but one of the tables I’m trying to join on doesn’t have all the columns for the objects primary key.
Example: (Note: This problem uses natural keys and the below is just an example to express the issue.)
Event Table:
Application (PK)
Event Name (PK)
Filter ID (PK)
Event Description Table:
Application (PK)
Event Name (PK)
Description
I need to map the Event object (Expressed below) to these two tables.
Code:
public class Event
{
private String application;
private String event;
private int filterId;
private String String;
// setters, getters, equal, hashCode, etc..
}
My composite-id looks like:
Code:
<composite-id>
<key-property
name="application"
column="I_APPL"/>
<key-property
name="event"
column="C_EVNT_TYP"/>
<key-property
name="filterId"
column="I_EVNT_FILTER"
access="field"/>
</composite-id>
My join looks like:
Code:
<join
table="EVENT_TBL"
optional="true">
<key>
<column name="I_APPL"/>
<column name="C_EVNT_TYP"/>
</key>
<property
name="description"
column="T_EVNT_TYP"/>
</join>
But because I don’t have all of the columns that define the event in the Event Description table, I receive an error because Hibernate tries to join on ALL of the composite-id fields. Anyone have a solution to this problem?