Search code examples
javahibernategrailshibernate-mapping

Getting error in executequery in hibernate


I have written a hql query in grails inside controller and while executing it i am getting error such as

unexpected token: where near line 1, column 166 [FROM com.ashwin.Training tr where tr.id NOT IN (SELECT t.training_id from com.ashwin.User u INNER JOIN com.ashwin.TrainUser t on u.id=t.user_id where u.id=t.user_id where u.id=:uid)]".

MY Hibernate query is

def currentUser = springSecurityService.currentUser.id
def trainingList=Training.executeQuery("FROM Training tr where tr.id NOT IN (SELECT t.training_id from User u INNER JOIN TrainUser t on u.id=t.user_id where u.id=t.user_id where u.id=:uid)",[uid:currentUser])
             [trainingLists:trainingList]

enter image description here


Solution

  • In inner select you have this

    t on u.id=t.user_id where u.id=t.user_id where u.id=:uid
    

    Double where is incorrect. And also you already define join rule. So the correct statement is

    FROM Training tr where tr.id NOT IN 
        (SELECT t.training_id from User u INNER JOIN TrainUser t 
        on u.id=t.user_id where u.id=:uid)