Hi
I have a problem running native queries with hibernate.
When I execute this query:
Code:
SELECT T.orderNumber, G.orderNumber , T.supplierNumber, G.supplierNumber , T.customerNumber, G.customerNumber , T.dataSource, G.dataSource FROM orderdata AS T LEFT OUTER JOIN orderdata AS G ON T.orderNumber = G.orderNumber AND T.supplierNumber = G.supplierNumber AND G.dataSource = 'G' WHERE T.dataSource = 'T'
with this as data in the order data table (columns: dataSource, orderNumber, supplierNumber, customerNumber)
G 101967 O1 100999
G 101968 O1 100999
G 101969 O1 100999
T 101967 O1 100999
T 101968 O2 100999
T 101969 O1 49978
I expect to get this result (as returned by the eclipse sql scrap book):
101967 101967 100999 100999 O1 O1 T G
101968 101968 100999 100999 O2 O1 T G
101969 NULL 49978 NULL O1 NULL T NULL
Yet, when I execute this with Hibernate using this statement:
Code:
List result = em.createNativeQuery(sql).getResultList();
I get a String array with this values (notive that the second row should contain "O1 O2" and the 3rd the null values):
[101967, 101967, 100999, 100999, O1, O1, T, T]
[101968, 101968, 100999, 100999, O2, O2, T, T]
[101969, 101969, 49978, 49978, O1, O1, T, T]
Why? The value for the supplier number of 101969 (100999 vs. 49978) is different so hibernate should return null values as does the sql scrap book for these entries.
Thanks in advance for you help