Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Y-AH opened this issue Jan 10, 2024 · 2 comments
Closed

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

Y-AH opened this issue Jan 10, 2024 · 2 comments
Labels
in: query-parser Everything related to parsing JPQL or SQL type: bug A general bug

Comments

@Y-AH
Copy link

Y-AH commented Jan 10, 2024

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?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 10, 2024
@christophstrobl
Copy link
Member

Thanks for reporting - we'll have a look.

@christophstrobl
Copy link
Member

The parser only allows single quotes when parsing jpql. We're working on relaxing this restriction.

@mp911de mp911de changed the title JPQL Parsing Issue JPQL parser doesn't accept double-quoted string literals Jan 10, 2024
@mp911de mp911de added type: bug A general bug in: query-parser Everything related to parsing JPQL or SQL and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 10, 2024
mp911de pushed a commit that referenced this issue Jan 10, 2024
Closes #3308
Original pull request: #3280
mp911de pushed a commit that referenced this issue Jan 10, 2024
Closes #3308
Original pull request: #3280
@mp911de mp911de added this to the 3.1.8 (2023.0.8) milestone Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: query-parser Everything related to parsing JPQL or SQL type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants