Skip to content

BadJpqlGrammarException no viable alternative at input for reserved keyword: cannot escape #3056

@multanis63

Description

@multanis63

Hello,

Since 3.1.1, the following entity / query is not working anymore:

@Entity
@Table
public class TestEntity {

    @Id
    @Column(name = "ID")
    private Long id;

    @NotNull
    @Column(name = "TEST_TYPE", nullable = false)
    private String type;
    }
}
@Query(value = "select te from TestEntity te where te.type = :type")
List<TestEntity> findByType(@Param("type") String type);

Result: org.springframework.data.jpa.repository.query.BadJpqlGrammarException: Line 1:34 no viable alternative at input 'te.type'; Bad JPQL grammar

Seems related to #2791 but I cannot make it work.
I'm not using Hibernate but eclipselink with h2.

What I've tried (all not working):

@Query(value = "select te from TestEntity te where te.`type` = :type")
List<TestEntity> findByType(@Param("type") String type);

@Query(value = "select te from TestEntity te where te.\"type\" = :type")
List<TestEntity> findByType(@Param("type") String type);

@Query(value = "select te from TestEntity te where te.type = :testType")
List<TestEntity> findByType(@Param("testType") String type);

@Query(value = "select te from TestEntity te where te.type2 = :type")
List<TestEntity> findByType(@Param("type") String type);

The only way to make it work is by renaming BOTH entity field and query param:

@Query(value = "select te from TestEntity te where te.type2 = :testType")
List<TestEntity> findByType(@Param("testType") String type);

Or to not use JPQL (but that's not the goal):

List<TestEntity> findByType(String type);

Thanks,

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions