I'm working with a flattened database view, where it doesn't have a good primary key design. It looks like this:
column A (not null)
column B (not null)
column C (nullable)
Where sometimes column C is used to identify between rows, and sometimes it's null, and it is assumed A and B are enough to uniquely identify a row.
e.g. You could have data like this:
A B C
1 1 1
1 1 2
1 2 null
The problem is, I'm not sure how to model my mapping.
If I model it so that column C is part of the composite-id, then that third row I get back in a query is completely null. e.g. The list.size() is 3, but only two of the elements are populated.
But if I just treat column C as a property of Foo and not part of FooId, then I only get two rows back in a query, and the data returned is a duplicate of row 1.
Am I missing something basic here, or is this type of mapping not currently allowed? TIA.
Here's what my mapping looks like:
Code:
<hibernate-mapping>
<class name="Foo" table="foo">
<composite-id name="id" class="FooId">
<key-property name="a" type="java.lang.String" column="a"/>
<key-property name="b" type="java.lang.String" column="b"/>
<key-property name="c" type="java.lang.String" column="c"/>
</composite-id>
<property name="d" type="java.lang.String" column="d"/>
<property name="e" type="java.lang.String" column="e"/>
</class>
</hibernate-mapping>
public class Foo implements Serializable {
private FooId;
private String d;
private String e;
}
public class FooId implements Serializable {
private String a;
private String b;
private String c;
// implemented equals and hashcode, allowing for c to be null
}