1

Im getting a org.hibernate.hql.internal.ast.QuerySyntaxException in my query

Query query = session.createQuery("update Room as r "
            + "inner join Booking as b "
            + "on r.roomId = b.room.roomId "
            + "set r.roomAvailable = true "
            + "where b.checkOutDate < NOW()");

full error:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: expecting "set", found 'inner' near line 1, column 55 [update com.websystique.springsecurity.model.Room as r inner join com.websystique.springsecurity.model.Booking as b on r.roomId = b.room.roomId set r.roomAvailable = true where b.checkOutDate < NOW()]

the query is working fine in mysql workbench... so is this possible in anyway here in code or not?

Any help greatly appreciated.

4
  • 2
    the query is working fine in mysql workbench: mysql workbench executes SQL queries. session.createQuery expects an HQL query. Those are two different languages. Commented Feb 15, 2017 at 19:45
  • 2
    you need to use createSqlQuery insted of createQuery Commented Feb 15, 2017 at 19:46
  • @mvlaicevich Thanks buddy! Commented Feb 15, 2017 at 20:50
  • @john you're welcome! Commented Feb 15, 2017 at 21:03

1 Answer 1

1

You have to use a query with a subselect instead of a join. Rewrite your query and it will work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.