Hibernate 3, Oracle 9i.
I've got a problem creating a one-to-many association between two tables. Essentially the foreign-key column in the child object is not actually a column but is the result of a
forumla property mapping. I can't work out how to declare the mapping either way. What I would ideally like is tobe able to declare an association between a column on the parent and a property on the child but I can't see a way of doing this.
For example, in the child I've tried using the following. The name of the column is the actual name of the property.
Code:
<many-to-one
name="subIndustry"
class="com.db.csa.systems.r1.domain.SubIndustry"
not-null="true"
foreign-key="false"
column="parentSectorId"
/>
Obviously this doesn't work as there is no olumn in the table called parentSectorId. So I've tried using the property-ref instead, but this is used to determine which property is used in the parent, not the child. So, I'm now stuck.
I have issues with the schema which limit what I can actually do. The tables actually map out a many-to-many relationship between the child and the parent but this doesn't reflect the business logic so I want to map it as a one-to-many. I don't own the schema so I can't change it. Also there is another table which restricts some of the data returned that I need to include to further complicate things.
As a final attempt I tried changing the mapping file to use a <subselect> instead of a table declaration. This caused different issues as I ended up with Oracle errors around how a single-row subquery was returning more than one row (Duh, its a subselect, what do you expect?), only when a where clause was added to the subselect by Hibernate when trying to do the associations. Nice.
So, I'm now stuck. And I need so help. Can anyone out there help?
Thanks,
Rob