I'm trying to reproduce the results of a single SQL call in Hibernate - but so far no luck.
The SQL query is:
Code:
SELECT BN.*, OP.*, MA.*, DOC.*
FROM BOM_NODE BN
LEFT OUTER JOIN MATERIAL MA ON BN.DOCUMENT_ID = MA.ID AND BN.DOCUMENT_TYPE = 'M'
LEFT OUTER JOIN OPERATION OP ON BN.DOCUMENT_ID = OP.ID AND BN.DOCUMENT_TYPE = 'O'
LEFT OUTER JOIN DOCUMENT DOC ON BN.DOCUMENT_ID = DOC.ID AND BN.DOCUMENT_TYPE = 'D'
WHERE BN.DOCUMENT_TYPE IN ('M', 'O', 'D')
If I use createSQLQuery(String query) to retrieve a list of bojects from the database, Hibernate only returns null values from the Operation and Document tables whereas running the query directly against SQL Server 2008 I get all the expected results.
If I define many-to-one properties in the BOM_NODE mapping doucment, Hibernate executes a query for each table (unsatisfactory).
I'd welcome any advice towards soultion that allows me to retrieve the entire graph of data via Hibernate with a single query.