nordborg wrote:
This seems really strange. If it really behaves like that I would conisder it a bug. The entire feature of doing scalar queries would more or less be useless.
But... I made a test of my own and I could not reproduce this. All Object-arrays are of the same size and null values appear at the expected places.
I am using Hibernate 3.3.0.sp1
Here is my test code:
Code:
org.hibernate.Query q = session.createQuery(
"select name, description, startDate from NewsData where id=43711");
List<Object[]> l = q.list();
for (Object[] row : l)
{
for (int i = 0; i < row.length; ++i)
{
System.out.println(i+"=" + row[i]);
}
}
And the output:
Code:
0=New news
1=null
2=2009-03-25
nordborg, thanks for you post. You result is very interesting... Unfortunately, I can not tell now which version of hibernate I use at work but I reproduced similar behavior on my laptop with hibernate 3.2.6 ga.
But I found a solution. It's quite simple:
SELECT coalesce(lastName, ''), coalesce(lastName, '') FROM Person WHERE id = 1;
Perhaps this will be useful to somebody.