简体   繁体   中英

java.lang.IllegalArgumentException: Name for parameter binding must not be null or empty

I'm currently getting this error regarding my jqpl query for ordering:

Name for parameter binding must not be null or empty! On JDKs < 8, you need to use @Param for named parameters, on JDK 8 or better, be sure to compile with -parameters

I'm on the former situation, so I need to use @Param but I'm unsure how to do this. This is the situation currently regarding my JPQL:

@Query("SELECT p FROM DePerson p, DeClass c, DeSchool s" +
    "WHERE p.personId = c.id " +
    "AND su.schoolId = s.id " +
    "ORDER BY :ordering")
Page<DeSiteUser> orderingAll(Page page, String ordering, Pageable pageable);

So it's clear as day I need to implement @Param for the values I'm trying to pass in the ordering string. What I'm trying to achieve is implementing an ordering method that would allow a value such as:

http://localhost:8080/api/person?sorting=city

The value city to be passed into the query and then sort out the information based on that. That being the case, how would I pass in the @Param for my existing jpql to enable it to 1. work but 2. allow the ability for ordering. Thank you.

If you use Java version later than 8 you have to paste this into Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler:

-parameters

And in gradle.build:

compileJava {
    options.compilerArgs << '-parameters'
}

Use @Param("ordering")

@Query("SELECT p FROM DePerson p, DeClass c, DeSchool s" +
    "WHERE p.personId = c.id " +
    "AND su.schoolId = s.id " +
    "ORDER BY :ordering")
Page<DeSiteUser> orderingAll(@Param("ordering") String ordering, Pageable pageable);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM