Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aop.AopInvocationException: Null return value from

Tags:

spring-mvc

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?

like image 247
JSO Avatar asked May 04 '16 13:05

JSO


2 Answers

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

like image 187
Entea Avatar answered Nov 01 '22 17:11

Entea


@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)

like image 44
S RB Avatar answered Nov 01 '22 17:11

S RB