• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HQL Deletion fail

 
Ranch Hand
Posts: 48
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I have this HQL Get Query which works just fine:

In an other method, I have the following HQL which cases an "unexpected token: inner":

As you see, the only difference between these two queries is that the second one begins with an delete keyword.

Full code:


Why do the second one fail?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi P Marksson,

First of all, a warm welcome to CodeRanch!

P Marksson wrote:Why do the second one fail?


Probably because you can't use INNER JOIN in a DELETE statement. And that's confirmed in the Delete Queries section of the Java Persistence WikiBook. So you'll probably have to rewrite your query using a subquery instead.

Hope it helps!
Kind regards,
Roel
 
P Marksson
Ranch Hand
Posts: 48
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bumb! Thanks for the help! So I am trying to implement this using sub queries but can't get it to work. Have been reading tutorials and can't really see what's wrong.

I have the table URL which have a fk to table Group. The entities look like this:



This is the delete method:


This query throws an exception with no details.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

P Marksson wrote:This query throws an exception with no details.


Which exception do you get?

Could you try the simplest version of that query using nested properties?

If that doesn't work try something similar based on the group id

Hope it works!
Kind regards,
Roel

PS. It might be worth mentioning that Group might be interpreted as a HQL keyword as it is part of the GROUP BY clause. If it's an issue, try enclosing Group within square brackets ([Group]), single or double quotes.
 
P Marksson
Ranch Hand
Posts: 48
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Escaping Group with bracket, single or double quote actually resulted in org.hibernate.QueryException, where the escaped character being denoted as "unexpected".



The first snipped you suggested have I already tried. Just to make sure, I tried again with no luck. The exception was
Trying the last suggestion, I got exactly the same error.

A bad solution to this would be to get the group by name, and then scan the OneToMany-URL-List presented in the Group class, search for for the given URL and remove it. Really ugly.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

P Marksson wrote:The first snipped you suggested have I already tried. Just to make sure, I tried again with no luck. The exception was
Trying the last suggestion, I got exactly the same error.


That's a very descriptive exception you get! That's not related to the query itself, but due to the lack of a transaction. You need a transaction to execute an update/delete query. So there seems to be something wrong with your configuration...
reply
    Bookmark Topic Watch Topic
  • New Topic