]
Patras Vlad commented on HHH-5353:
----------------------------------
When using JDBC statemnts the data is correct.
I din't try Query Analyser but the data is correct in SQL Explorer (eclipse based
database IDE).
Incorrect results for Ms SQL native queries with anonymous columns
------------------------------------------------------------------
Key: HHH-5353
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5353
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.3
Environment: Hibernate 3.5.3
Ms SQL Server 2005
Reporter: Patras Vlad
Priority: Minor
MS Sql Server does not name columns if they are not explicitly named or selected from a
concrete table column. I presume hibernate uses the column name as a key and this causes
incorrect results.
Fo example add the following method to a test:
{noformat} public void testNoNameColumns() {
Session s = openSession();
Transaction t = s.beginTransaction();
List l = s.createSQLQuery( "select 'A', 'B'" ).list();
assertEquals( 1, l.size() );
assertEquals( "A", ((Object[])l.get(0))[0] );
assertEquals( "B", ((Object[])l.get(0))[1] );
t.rollback();
s.close();
}{noformat}
The third assert will fail if you run it against a Ms SQL Server database. It passes with
default database (used in a clean svn checkout).
No matter what the values are selected, if columns have no name, all will have the value
of the first column. This also happens when selecting from a table and using a formula in
the select:
{noformat}select a+b, c+d from abcdTable{noformat}
I don't expect an actual fix since it happens in rare cases, only on Ms SQL Server
and the workaround is very simple (just add a name using "AS" keyword). However
when this happens it may be difficult to find the cause, maybe if you could throw an
exception if the query returns more than one unnamed column.
Note: I'm not sure if these columns have an associated term, I called them
"anonymous columns" and "unnamed columns", Ms SQL Server Management
Studio titles them "(no column name)".
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: