Hi,
Bit of a newbie here and I'm sure this question must have been answered before, but I couldn't find it anywhere in the Forum or FAQ.
Anyway, my problem relates to performing a simple Select. The line of code in question is as follows:
List result = session .createSQLQuery(sql) .addEntity("tableRef", getDataClass()) .list();
'sql' above is simply a String which resolves to:
SELECT {tableRef.*} FROM My_View tableRef WHERE (UPPER(SUR_NAME) LIKE 'B%' OR UPPER(MAIDEN_NAME) LIKE 'B%') AND EMPLOYEE_TYPE = 'EMPLOYEE' ORDER BY My_ViewDesc
I'm assuming that the 'addEntity' bit simply substitutes the 'tableRef' above with whatever is returned by the getDataClass() method, which is simply 'My_ViewData'
If the above didn't make any sense then don't worry. The crux of my problem is as follows...
I'm fairly sure that the above code results in the following SQL being generated:
SELECT * FROM My_View WHERE (UPPER(SUR_NAME) LIKE 'B%' OR UPPER(MAIDEN_NAME) LIKE 'B%') AND EMPLOYEE_TYPE = 'EMPLOYEE' ORDER BY My_ViewDesc
When I execute this SQL in something like Toad, 79 results are returned. And when I run the above Java code, the List called 'result' does indeed contain 79 elements as you would expect. However, each List element is NULL.
Why isn't my List being populated with the values from the database? Obviously it must be doing SOME sort of Select if 79 elements are being returned, but each of them should not be null.
The database 'table' in question is actually a View, although I wouldn't have thought this would have made any difference...(?)
Sorry for the rambling nature of this post but as you've probably gathered, this is all fairly new to me.
Thanks in advance.
|