jpaRepository Отличный метод не работает - PullRequest
0 голосов
/ 15 мая 2018

Я хочу найти уникальных сотрудников из моей таблицы, я использую JPArepository

public List<String> findDistinctempName();

Я получаю исключение при запуске сервера как

No property findDistinctempName found for type Employee !

at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:79) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:335) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:311) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:274) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:245) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:247) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:398) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:378) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:86) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:70) ~[spring-data-jpa-1.11.11.RELEASE.jar:na]
... 52 common frames omitted

может кто-нибудь предложить мне найти уникальные строки таблицы, имеющие разные empName и номер мобильного телефона

Ответы [ 2 ]

0 голосов
/ 15 мая 2018

Вы не можете получить отдельные записи с помощью findBy ... вам нужно создать собственный запрос, чтобы получить желаемый результат.Вы можете получить уникальные записи с помощью группировки по.Пожалуйста, найдите код хранилища ниже, чтобы получить все автомобили с группой по имени и идентификатору.

    public interface CarRepository extends JpaRepository<Car, Integer>, JpaSpecificationExecutor {

        @Query("select car from Car car group by car.name,car.id")
        List<Car> findDistinctByName();

    }


    @Entity
    public class Car {

        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "car_id")
        int car_id;
        String name;

    }
0 голосов
/ 15 мая 2018

Вам нужно верблюдовать имя вашего метода, а также отдельные предикаты с помощью by

findDistinctByEmpName();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...