Hibernate Delete using HQL – QuerySyntaxException: Foo is not mapped

The entity name needs to be used in the query instead of the table name.

 

For example this causes the QuerySyntaxException as it uses the database table name in the query:

 

Query query = session.createQuery(“delete from product¬†where venue_id = :venueID”);
query.setParameter(“venueID”, venueID);

The below query works as it uses the entity name:

Query query = session.createQuery(“delete from ProductEntity¬†where venue_id = :venueID”);
query.setParameter(“venueID”, venueID);