tried the entire app with mysql but faced same problem with it, so continueing hsqldb and luckly the modified query for hierarchy works