Skip to content

JPQL parser doesn't accept double-quoted string literals #3308

@Y-AH

Description

@Y-AH

While parsing JPQL in @Query annotation, the parsing removes the " from the query itself resulting in an invalid query passed to hibernate.

Sample:
Inside SampleRepository

    @Query("select new com.example.demo.SampleObject(se.id, se.sampleValue, \"\") from SampleEntity se")
    List<SampleObject> getAllSampleObjects();

SampleObject.java

@Data
@AllArgsConstructor
public class SampleObject {

    private Long id;
    private String sampleValue;
    private String additionalValue;

}

SampleEntity.java

@Entity
@Getter
@Setter
public class SampleEntity {

    @GeneratedValue
    @Id
    private Long id;

    private String sampleValue;

}

The above code result in (spring 3.2.1)

org.hibernate.query.SyntaxException: At 1:63 and token ')', no viable alternative at input 'select new com.example.demo.SampleObject(se.id, se.sampleValue,*) from SampleEntity se' [select new com.example.demo.SampleObject(se.id, se.sampleValue,) from SampleEntity se]
	at org.hibernate.query.hql.internal.StandardHqlTranslator$1.syntaxError(StandardHqlTranslator.java:108) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]

In spring 3.1.7

org.hibernate.query.sqm.ParsingException: line 1:63 no viable alternative at input 'selectnewcom.example.demo.SampleObject(se.id,se.sampleValue,)'
	at org.hibernate.query.hql.internal.StandardHqlTranslator$1.syntaxError(StandardHqlTranslator.java:46) ~[hibernate-core-6.2.17.Final.jar:6.2.17.Final]

The issue first encountered when migrating from spring boot 3.0 to 3.1. Also I noticed in spring 3.0 the QueryEnhancer does not do anything if the query does not have sorting, is there a reason why the new one tries to parse even if there is no sorting?

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: query-parserEverything related to parsing JPQL or SQLtype: bugA general bug

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions