6

I'm performing a SQL query through hibernate, which looks like:

@Query("(select category from Category category where category.isDelete=false and category.status='A' AND " +
        "category.id in (select cat.id from Category cat where cat.isDelete=false and cat.status='A' and cat.parentCategory IS NOT NULL))" +
        "UNION" +
        "(select category from Category category where category.isDelete=false and category.status='A' and category.parentCategory IS NOT NULL)")

But it showing me error

Caused by: java.lang.IllegalArgumentException: node to traverse cannot be null!

2 Answers2

5

your query is fine at sql level, but in case of Hibernate you will face this exception

Caused by: java.lang.IllegalArgumentException: node to traverse cannot be null!

so convert this query

@Query("(select category from Category category where category.isDelete=false and category.status='A' AND " +
    "category.id in (select cat.id from Category cat where cat.isDelete=false and cat.status='A' and cat.parentCategory IS NOT NULL))" +
    "UNION" +
    "(select category from Category category where category.isDelete=false and category.status='A' and category.parentCategory IS NOT NULL)")

into two queries

@Query("select category from Category category where category.isDelete=false and category.status='A' AND " +
    "category.id in (select cat.id from Category cat where cat.isDelete=false and cat.status='A' and cat.parentCategory IS NOT NULL)")

@Query("select category from Category category where category.isDelete=false and category.status='A' and category.parentCategory IS NOT NULL")

and call them by different methods.

Dev Sabby
  • 1,367
  • 1
  • 11
  • 17
1

How do you select category is their any field like that and you have mentioned you category table as category fix it then try either other approach is alright *you can check it also by giving asterisk as * and your rest of the query is correct*