Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate generating bad syntax sql

There are two tables: bb_players and bb_player_skills. player skills table has one to one relation with bb_players, and also foreign key to bb_players.

Error happens at executing this code:

Query q = em.createNamedQuery(PlayerSkill.DELETE_SKILL_BY_PLAYER_ID);
q.setParameter("playerID", playerID);
q.executeUpdate();

The named query is:

 @NamedQuery(name = PlayerSkill.DELETE_SKILL_BY_PLAYER_ID, query = "DELETE FROM   PlayerSkill s " +
 " WHERE s.player.id = :playerID")

The error from postgresql logs is:

ERROR,42601,"syntax error at or near ""cross""",,,,,, 
 "delete from bb_player_skills cross join bb_players player1_ where id=$1",30,,""

Is my named query wrong and how should I rewrite it?

like image 597
maximus Avatar asked Dec 24 '22 14:12

maximus


1 Answers

It appears that this may be an open Hibernate issue depending on your Hibernate version.

From: https://hibernate.atlassian.net/browse/HHH-7314

Using a JPA Delete query with conditions requiring a join through Hibernate entity-manager generates invalid SQL for PostgreSQL. PostgreSQL cannot use CROSS JOIN in the FROM clause of a DELETE query.

like image 161
Nate Avatar answered Dec 30 '22 11:12

Nate