I've recently upgrade from hibernate 3.5 to 4.3.11 with Spring 4.3.9 Before the upgrade everything was working fine. After the upgrade I get this error.
Environment: Java 8, Tomcat 7.0.23, Hibernate 4.3.11, Spring 4.3.9, MSSQL Server 2008,
While executing the following sql query through hibernate, we are getting list of null object with correct size in the list but object are null.
Query:
select DISTINCT(HIERARCHY_ID) from BASETYPE_HIERARCHY_MAPPING
where BASETYPE_ID IN (select BASETYPE_ID from BASETYPE_GROUP_MAPPING
where GROUP_ID IN (select GROUP_ID from USER_GROUP_MAPPING where USER_ID like(select ID from USER where USERID='7')))
Java Code:
String sqlQuery="select DISTINCT(HIERARCHY_ID) from BASETYPE_HIERARCHY_MAPPING where BASETYPE_ID IN "
+ "(select BASETYPE_ID from BASETYPE_GROUP_MAPPING where GROUP_ID IN "
+ "(select GROUP_ID from USER_GROUP_MAPPING where USER_ID=(select ID from USER where USERID=:userId)))";
Query query = session.createSQLQuery(sqlQuery);
query.setParameter("userId", userId);
List<String> typeId = query.list();
In result list of null objects.I have found similar type of issue for HQL(solution was mistake in mapping) but its simple sql query.
Similar Issue reference link: Hibernate returns list of nulls although executed SQL returns values