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

Improve exception message for missing parameter names on JDK 8 [DATAJPA-1086] #1427

Closed
spring-projects-issues opened this issue Apr 4, 2017 · 6 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Apr 4, 2017

Peter Rader opened DATAJPA-1086 and commented

The constructor of StringQueryParameterBinder is not JDK8 Compatible. The first constructor StringQueryParameterBinder(JpaParameters parameters, Object[] values, StringQuery query) expect parameter-names in "parameters" but the names are in "query".

example:

public interface B {
    @Query("SELECT b FROM B b WHERE b.id = :bid")
    Set<B> findB(long bId);
}

Exception:

Caused by: java.lang.IllegalArgumentException: Name for parameter binding must not be null or empty! For named parameters you need to use @Param for query method parameters on Java versions < 8.
	at org.springframework.util.Assert.hasText(Assert.java:168)
	at org.springframework.data.jpa.repository.query.StringQuery.getBindingFor(StringQuery.java:110)
	at org.springframework.data.jpa.repository.query.StringQueryParameterBinder.getBindingFor(StringQueryParameterBinder.java:75)
	at org.springframework.data.jpa.repository.query.StringQueryParameterBinder.bind(StringQueryParameterBinder.java:60)
	at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:100)

Affects: 1.11 GA (Ingalls)

Attachments:

Backported to: 1.11.4 (Ingalls SR4), 1.10.11 (Hopper SR11)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 12, 2017

Oliver Drotbohm commented

Do you have a sample project reproducing that? To use named parameters in @Query you need to either compile with -parameters or use @Param annotations on the query method parameters

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 16, 2017

Peter Rader commented

Attached project

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 16, 2017

Oliver Drotbohm commented

The app's build doesn't actually fail for me. mvn clean package just succeeds. However, at a quick glance, I don't see you having configured the compiler plugin to use -parameters, which I indicated is needed above

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 16, 2017

Peter Rader commented

To execute the example-project you have to call mvn compile exec:java.

I never heard of -parameters name, can you forward me to official documentation? Afaik on DATAJPA we must use @Param and the Java8 Metadatas are ignored.

Even if the -parameters flag must be set it should be part of the exceptions's message, what is currently not

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 17, 2017

Oliver Drotbohm commented

First Google hit is this.

Adding this does the trick:

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<configuration>
				<compilerArgument>-parameters</compilerArgument>
			</configuration>
		</plugin>
	</plugins>
</build>
@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 17, 2017

Oliver Drotbohm commented

Improved exception message explicitly hinting at -parameters is in place

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants