简体   繁体   中英

When loading a spring context, the repository bean is not created

I am trying to create a repository but getting an error.

My interface repository:

public interface CallRepository extends JpaRepository<Call, Integer> {

    @Override
    @Transactional
    Call save(Call call);

    @Modifying
    @Transactional
    @Query("DELETE FROM Call c WHERE c.id=:id AND c.subscriber.id=:subscriberId")
    int delete(@Param("id") int id, @Param("subscriberId") int subscriberId);

    @Query("SELECT Call FROM Call c WHERE  c.subscriber.id=:subscriberId")
    List<Call> getAll(@Param("subscriberId") int subscriberId);

    List<Call> getAllBySubscriberIdAndDateTimeBetween(int subscriberId, LocalDateTime startDateTime, LocalDateTime endDateTime);

} 

My repository class:

@Repository
public class CallRepositoryImpl {

    @Autowired
    private SubscriberRepository subscriberRepository;

    @Autowired
    private CallRepository repository;

    @Transactional
    public Call save(Call call, int subscriberId) {
        if (!call.isNew() && get(call.getId(), subscriberId) == null) {
            return null;
        }
        call.setSubscriber(subscriberRepository.getOne(subscriberId));
        return repository.save(call);
    }

    public Call get(int id, int subscriberId) {
        return repository.findById(id)
                .filter(t -> t.getSubscriber().getId() == subscriberId)
                .orElse(null);
    }

    public boolean delete(int id, int subscriberId) {
        return repository.delete(id, subscriberId) != 0;
    }

    public List<Call> getAll(int subscriberId) {
        return repository.getAll(subscriberId);
    }

    public List<Call> getBetweenDateTime(int subscriberId, LocalDateTime startDateTime, LocalDateTime endDateTime) {
        Objects.requireNonNull(startDateTime, "startDateTime must not be null");
        Objects.requireNonNull(endDateTime, "endDateTime must not be null");
        return repository.getAllBySubscriberIdAndDateTimeBetween(subscriberId, startDateTime, endDateTime);
    }

}

When loading the spring context, I get an error:

Error creating bean with name 'callRepositoryImpl': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'callRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List ru.subscribers.repository.events.CallRepository.getAll(int)!

In database "id" with type Integer, in entity "id" with type Integer also.

Tell me what could be the problem?

I'm not sure, but shouldn't query be like that?

@Query("SELECT c FROM Call c WHERE  c.subscriber.id=:subscriberId")

Can you show me your context file?

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