Reputation: 2140
I'm aware of this question, but using org.springframework.data:spring-data-jpa:1.7.0.RELEASE
I'm still having the same issue (Either use @Param on all parameters except Pageable and Sort typed once, or none at all!
). My class is:
public interface BalanceHistoryRepository extends JpaRepository<BalanceHistory, Long> {
@Query("select bh from BalanceHistory bh where bh.account.id = :idAccount")
public BalanceHistory findCurrentBalanceByAccountNumber(PageRequest pageCriteira, @Param("idAccount") long idAccount);
}
Edit
Call:
Pageable page = new PageRequest(0, 1, Sort.Direction.DESC, "date");
BalanceHistory bh = balanceHistoryRepository.findCurrentBalanceByAccountNumber(1,page);
Method:
@Query("select bh from BalanceHistory bh where bh.account.id = :idAccount")
public BalanceHistory findCurrentBalanceByAccountNumber(@Param("idAccount") long idAccount, Pageable pageCriteira);
Upvotes: 15
Views: 21537
Reputation: 763
I solved it using the following query
@Query("SELECT c FROM yourTable c where c.isActive=?1 and c.isDelete='N' ORDER BY c.companyAccId DESC")
Page<yourTable > findAllByIsActiveAndIsDelete( String isActive,Pageable pageable);
Upvotes: 0
Reputation: 17328
I encountered the same exception when I accidentally imported the wrong Pageable
class.
This can also happen if you use PageRequest
in the repository as well.
it should be,
import org.springframework.data.domain.Pageable;
Upvotes: 3
Reputation: 83071
Make sure you use Pageable
instead of PageRequest
so that the first parameter is recognized as one not to be bound to the actual query. Also, you need to change the return type to either Page
or List
as you'll return multiple results mostly.
public interface BalanceHistoryRepository extends CrudRepository<BalanceHistory, Long> {
@Query("select bh from BalanceHistory bh where bh.account.id = :idAccount")
Page<BalanceHistory> findCurrentBalanceByAccountNumber(@Param("idAccount") long idAccount, Pageable pageable);
}
This should do the trick. Note, that we generally recommend not to extend the store specific interfaces as they expose store-specific API that should only be exposed if really necessary.
Upvotes: 26