在创建custome方法查询时,找不到Employee类型的属性Employee?

0s7z1bwu  于 2021-07-11  发布在  Java
关注(0)|答案(1)|浏览(449)

我有一个扩展了jparepository的emplyoerepo,我创建了下面给出的两个方法,它们包含服务层和服务实现层,但是当我运行的程序出现以下类型的错误时,我不知道如何解决这些问题,请帮助我。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emplyoeRepo': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.infodev.training.rohit.crudeoperation.Entity.Emplyoee com.infodev.training.rohit.crudeoperation.repository.EmplyoeRepo.findByEmplyoee_email(java.lang.String)! No property emplyoee found for type Emplyoee!
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:176) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1828) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1265) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:624) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:612) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.data.repository.config.DeferredRepositoryInitializationListener.onApplicationEvent(DeferredRepositoryInitializationListener.java:51) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.repository.config.DeferredRepositoryInitializationListener.onApplicationEvent(DeferredRepositoryInitializationListener.java:36) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:898) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) ~[spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at com.infodev.training.TrainingApplication.main(TrainingApplication.java:10) ~[classes/:na]
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract com.infodev.training.rohit.crudeoperation.Entity.Emplyoee com.infodev.training.rohit.crudeoperation.repository.EmplyoeRepo.findByEmplyoee_email(java.lang.String)! No property emplyoee found for type Emplyoee!
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:96) ~[spring-data-jpa-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:107) ~[spring-data-jpa-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:218) ~[spring-data-jpa-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:81) ~[spring-data-jpa-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:99) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(QueryExecutorMethodInterceptor.java:92) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[na:na]
    at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133) ~[na:na]
    at java.base/java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1054) ~[na:na]
    at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na]
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[na:na]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.mapMethodsToQuery(QueryExecutorMethodInterceptor.java:94) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lambda$new$0(QueryExecutorMethodInterceptor.java:84) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at java.base/java.util.Optional.map(Optional.java:265) ~[na:na]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.<init>(QueryExecutorMethodInterceptor.java:84) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:332) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.util.Lazy.getNullable(Lazy.java:211) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.util.Lazy.get(Lazy.java:95) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:244) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:57) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:169) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    ... 24 common frames omitted
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property emplyoee found for type Emplyoee!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:382) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:311) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at java.base/java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:330) ~[na:na]
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:293) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:276) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:82) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new$0(PartTree.java:251) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[na:na]
    at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177) ~[na:na]
    at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na]
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[na:na]
    at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:252) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new$0(PartTree.java:381) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[na:na]
    at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177) ~[na:na]
    at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na]
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[na:na]
    at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:382) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:97) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:89) ~[spring-data-jpa-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    ... 49 common frames omitted

我的实体类是:-

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "emplyoee")
public class Emplyoee {
    @Id
    @GeneratedValue
    @Column(name = "Id")
    private int Emplyoee_Id;

    @Column(name = "emplyoee_name")
    private String  emplyoee_name;

    @Column(name = "emplyoee_address")
    private String emplyoee_address;

    @Column(name = "emplyoee_email")
    private String  emplyoee_email;

}

我的服务layer:-

public interface EmplyoeeService {
    Emplyoee saveEmplyoee(Emplyoee emplyoee);

    List<Emplyoee> saveEmplyoees(List<Emplyoee> emplyoee);

    List<Emplyoee> getEmplyoee();

    Emplyoee getEmplyoeeById(int emplyoee_Id);

    String deleteEmplyoeeById(int emplyoee_Id);

    Emplyoee editEmplyoee(Emplyoee emplyoee);

    Emplyoee editEmplyoee1(int id, Emplyoee emplyoee);

    Emplyoee getEmplyoeeByName(String emplyoee_name);

    Emplyoee getEmplyoeeByEmail(String emplyoee_email);
}

我的serviceimpl类是:-

@Service
public class EmplyoeServiceImpl implements EmplyoeeService {
    @Autowired
    private EmplyoeRepo emplyoeRepo;

    @Override
    public Emplyoee saveEmplyoee(Emplyoee emplyoee) {

        return emplyoeRepo.save(emplyoee);
    }

    @Override
    public List<Emplyoee> saveEmplyoees(List<Emplyoee> emplyoee) {

        return emplyoeRepo.saveAll(emplyoee);
    }

    @Override
    public List<Emplyoee> getEmplyoee() {
        return emplyoeRepo.findAll();
    }

    @Override
    public Emplyoee getEmplyoeeById(int emplyoee_Id) {
        return emplyoeRepo.findById(emplyoee_Id).orElse(null);
    }

    @Override
    public Emplyoee getEmplyoeeByName(String name) {

        return emplyoeRepo.findByEmplyoee_name(name);

    }

    @Override
    public Emplyoee getEmplyoeeByEmail(String email) {

        return emplyoeRepo.findByEmplyoee_email(email);

    }

    @Override
    public String deleteEmplyoeeById(int emplyoee_Id) {
        emplyoeRepo.deleteById(emplyoee_Id);
        return "emplyoee is removed " + emplyoee_Id;
    }

    @Override
    public Emplyoee editEmplyoee(Emplyoee emplyoee) {
        Emplyoee existingEmplyoee = emplyoeRepo.findById(emplyoee.getEmplyoee_Id()).orElse(null);
        existingEmplyoee.setEmplyoee_name(emplyoee.getEmplyoee_name());
        existingEmplyoee.setEmplyoee_email(emplyoee.getEmplyoee_email());
        existingEmplyoee.setEmplyoee_address(emplyoee.getEmplyoee_address());
        return emplyoeRepo.save(existingEmplyoee);
    }

    @Override
    public Emplyoee editEmplyoee1(int id, Emplyoee emplyoee) {
        Emplyoee existingEmpyoee = emplyoeRepo.findById(id).orElse(null);
        existingEmpyoee.setEmplyoee_name(emplyoee.getEmplyoee_name());
        existingEmpyoee.setEmplyoee_address(emplyoee.getEmplyoee_address());
        existingEmpyoee.setEmplyoee_email(emplyoee.getEmplyoee_email());
        return emplyoeRepo.save(existingEmpyoee);

    }
}

我的寄存课是:-

@Repository
public interface EmplyoeRepo extends JpaRepository<Emplyoee, Integer> {
    Emplyoee findByEmplyoee_name(String emplyoee_name);

    Emplyoee findByEmplyoee_email(String emplyoee_email);

}
swvgeqrz

swvgeqrz1#

下划线是spring数据jpa的保留字符。spring在准备查询时使用下划线来理解多个实体之间的关系。
解决方案是从实体字段中删除下划线。只要改变 emplyoee_nameemplyoeeName 以及 emplyoee_emailemplyoeeEmail ;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "emplyoee")
public class Emplyoee {
    @Id
    @GeneratedValue
    @Column(name = "Id")
    private int Emplyoee_Id;

    @Column(name = "emplyoee_name")
    private String  emplyoeeName;

    @Column(name = "emplyoee_address")
    private String emplyoeeAddress;

    @Column(name = "emplyoee_email")
    private String  emplyoeeEmail;

}

并更改存储库

@Repository
public interface EmplyoeRepo extends JpaRepository<Emplyoee, Integer> {
    Emplyoee findByEmplyoeeName(String emplyoee_name);

    Emplyoee findByEmplyoeeEmail(String emplyoee_email);

}

相关问题