here is the repository:
@Query(value = "select u.balance from User u where u.name=:name")
float toGetBalance(@Param("name") String name);
and here is the DAO interface:
boolean checkBalance(String userName, float totalPrice);
and here is the service
@Transactional(readOnly = true)
@Override
public boolean checkBalance(String userName, float totalPrice) {
if (userRepository.toGetBalance(userName) < totalPrice) {
return false;
} else {
return true;
}
}
and here is the error info:
org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public abstract float com.repository.UserRepository.toGetBalance(java.lang.String)
and the type of balance is float!
what's wrong?
Change the signature of your repository to
@Query(value = "select u.balance from User u where u.name=:name")
Float toGetBalance(@Param("name") String name);
And it will simply return null
if there is no such user in database with given name
@Query(value = "select u.balance from User u where u.name=:name")'
'Float toGetBalance(@Param("name") String name);
This exception arise because name not exist OR balance = NULL fpr the selected record in the table So the query results no output. Spring JPA not able to bind the result with Return type Float.
Null return value from advice does not match primitive return type for: public abstract float com.repository.UserRepository.toGetBalance(java.lang.String)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With