The problem I am having is caused by Account having a composite key of AccountNo and HoldingCompany. In its self this is easy to handle in Hibernate for loading your domain object graph. The problem lies in doing queries using HQL. EntitledPosition object also has a composite key of Account and Announcement. The problem lies when I want to do a query in HQL as follows from EntitledPosition where account = :account as I understand Hibernate should know that if I want to query for EntitledPosition using an Account object it needs to retrieve the two items in Account's composite key (AccountNo and HoldingCompany) and use these to look up EntitlePostion. If this was the case I would expect the following SQL:
Code:
select
AnnouncementID,
AccountNo,
HoldingCompany,
Qty
from
EntitlePos
where
AccountNo = ? and
HoldingCompany = ?
However instead Hibernate is generating the following SQL:
Code:
select
AnnouncementID,
AccountNo,
HoldingCompany,
Qty
from
EntitlePos
where
(
AccountNo, HoldingCompany
)=?
and this is not correct SQL syntax. If I change the problem so that Account only has AccountNo as its single primary key then then it works however this is not how the DB is setup.