vlad wrote:
Is it the HIERARCHY_ID really a String? That's a curious thing.
Otherwise, the SQL query looks fine. You should debug and see why it is not working because there is no indication why it shouldn't run as expected.
By the way, Hibernate 4 is no longer supported, so, if you want to benefit from bug fixes, you will have to upgrade to 5.2.
Yes it is String Type.
Solved the problem using hibernate scalar, by specifying the return type of column in query.
addScalar()Following changes are done in java code to solve the issue:
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).addScalar("HIERARCHY_ID", StringType.INSTANCE);
query.setParameter("userId", userId);
List<String> typeId = query.list();
But in our project lot of sql queries used, so I need to change in all queires any better soluation instead of this addScalar() or why its mandatory from hibernate 4, it was working fine in 3.5. Why we should mention type for every column ? As per Hibernate Documentation it's not mandatory.