-1

I'm with abstract class error e error creating bean with name.

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name .. Unsatisfied dependency expressed through field ......

I have the following error:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-03 17:13:43.819 ERROR 16180 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'projetoControleEstoqueApplication': Unsatisfied dependency expressed through field 'despacheRep'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'despacheRepository' defined in br.edu.iff.ProjetoControleEstoque.repository.DespacheRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List br.edu.iff.ProjetoControleEstoque.repository.DespacheRepository.findByFuncionario_respId(java.lang.Long,org.springframework.data.domain.Pageable)! No property funcionario found for type Despache!
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1413) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:917) ~[spring-context-5.3.4.jar:5.3.4]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:582) ~[spring-context-5.3.4.jar:5.3.4]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.3.jar:2.4.3]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[spring-boot-2.4.3.jar:2.4.3]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.4.3.jar:2.4.3]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.3.jar:2.4.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.3.jar:2.4.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) ~[spring-boot-2.4.3.jar:2.4.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) ~[spring-boot-2.4.3.jar:2.4.3]
    at br.edu.iff.ProjetoControleEstoque.ProjetoControleEstoqueApplication.main(ProjetoControleEstoqueApplication.java:24) ~[classes/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.4.3.jar:2.4.3]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'despacheRepository' defined in br.edu.iff.ProjetoControleEstoque.repository.DespacheRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List br.edu.iff.ProjetoControleEstoque.repository.DespacheRepository.findByFuncionario_respId(java.lang.Long,org.springframework.data.domain.Pageable)! No property funcionario found for type Despache!
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:657) ~[spring-beans-5.3.4.jar:5.3.4]
    ... 26 common frames omitted
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List br.edu.iff.ProjetoControleEstoque.repository.DespacheRepository.findByFuncionario_respId(java.lang.Long,org.springframework.data.domain.Pageable)! No property funcionario found for type Despache!
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:96) ~[spring-data-jpa-2.4.5.jar:2.4.5]
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:107) ~[spring-data-jpa-2.4.5.jar:2.4.5]
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:218) ~[spring-data-jpa-2.4.5.jar:2.4.5]
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:81) ~[spring-data-jpa-2.4.5.jar:2.4.5]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:100) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(QueryExecutorMethodInterceptor.java:93) ~[spring-data-commons-2.4.5.jar:2.4.5]
    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:1056) ~[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:95) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lambda$new$0(QueryExecutorMethodInterceptor.java:85) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at java.base/java.util.Optional.map(Optional.java:258) ~[na:na]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.<init>(QueryExecutorMethodInterceptor.java:85) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:303) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:323) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.util.Lazy.getNullable(Lazy.java:230) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.util.Lazy.get(Lazy.java:114) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:329) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:144) ~[spring-data-jpa-2.4.5.jar:2.4.5]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845) ~[spring-beans-5.3.4.jar:5.3.4]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782) ~[spring-beans-5.3.4.jar:5.3.4]
    ... 36 common frames omitted
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property funcionario found for type Despache!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:90) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:437) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:413) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:366) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at java.base/java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:330) ~[na:na]
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:348) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:331) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:81) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new$0(PartTree.java:249) ~[spring-data-commons-2.4.5.jar:2.4.5]
    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:250) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new$0(PartTree.java:383) ~[spring-data-commons-2.4.5.jar:2.4.5]
    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:384) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:95) ~[spring-data-commons-2.4.5.jar:2.4.5]
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:89) ~[spring-data-jpa-2.4.5.jar:2.4.5]
    ... 62 common frames omitted

------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time:  9.453 s
Finished at: 2021-04-03T17:13:44-03:00
------------------------------------------------------------------------

I'm not able to solve it, what would it be?

Class Despache


import com.fasterxml.jackson.annotation.JsonManagedReference;
import java.io.Serializable;
import java.util.Objects;
import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;


@Entity
public class Despache implements Serializable{
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;
    @Column(nullable = false)
    @NotBlank(message = "Local de despache obrigatório.")
    @Length(max = 200, message = "Local de despache deve ter no máximo 200 caracteres")
    private String local_de_despache;
    @Column(nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    @NotNull(message="Data despache é obrigatório.")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Calendar data_hora_s;
    
  
    @ManyToOne
    @JoinColumn(nullable=false)
    @NotNull(message = "Funcionário obrigatório.")
    @Valid
    private Funcionario_resp funcionario_resp;
    @OneToOne
    @JoinColumn(nullable=false)
    @NotNull(message = "Produto obrigatório.")
    @Valid
    private Produto produto;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Funcionario_resp getFuncionario_resp() {
        return funcionario_resp;
    }

    public void setFuncionario_resp(Funcionario_resp funcionario_resp) {
        this.funcionario_resp = funcionario_resp;
    }
    

    public Produto getProduto() {
        return produto;
    }

    public void setProduto(Produto produto) {
        this.produto = produto;
    }

    public String getLocal_de_despache() {
        return local_de_despache;
    }

    public void setLocal_de_despache(String local_de_despache) {
        this.local_de_despache = local_de_despache;
    }

    public Calendar getData_hora_s() {
        return data_hora_s;
    }

    public void setData_hora_s(Calendar data_hora_s) {
        this.data_hora_s = data_hora_s;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 19 * hash + Objects.hashCode(this.id);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Despache other = (Despache) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }

    public Despache() {
    }
    
    
    
}

Despache Repository:

package br.edu.iff.ProjetoControleEstoque.repository;

import br.edu.iff.ProjetoControleEstoque.model.Despache;
import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;


@Repository
public interface DespacheRepository extends JpaRepository<Despache, Long>{
    
    public List<Despache> findByFuncionario_respId(Long funcionario_respId, Pageable page);
  
    public List<Despache> findByProdutoId(Long produtoId, Pageable page);


}

Application Projeto Controle Estoque

package br.edu.iff.ProjetoControleEstoque;



import br.edu.iff.ProjetoControleEstoque.model.Despache;
import br.edu.iff.ProjetoControleEstoque.model.Funcionario_resp;
import br.edu.iff.ProjetoControleEstoque.model.Produto;
import br.edu.iff.ProjetoControleEstoque.repository.DespacheRepository;
import java.util.Calendar;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ProjetoControleEstoqueApplication implements CommandLineRunner{

       @Autowired
        private DespacheRepository despacheRep;
  
        
    public static void main(String[] args) {
        SpringApplication.run(ProjetoControleEstoqueApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        

        
        //Funcionario resp
        
        Funcionario_resp fr1 = new Funcionario_resp();
        fr1.setNome("Carol");
        fr1.setEmail("carol@gmail.com");
        fr1.setCpf("103.609.070-16");
        fr1.setUsuario("Jane");
        fr1.setSenha(698696);
        
  
        //Produto
        
        Produto p1 = new Produto();
        
        p1.setNome("Geladeira");
        p1.setCategoria("Eletrodomestico");
        p1.setPeso((int) 10.00);
   
      
        //Despache
        
        Despache d = new Despache();
        d.setFuncionario_resp((Funcionario_resp) List.of(fr1));
        d.setProduto((Produto) List.of(p1));
        d.setLocal_de_despache("Rio de Janeiro");
     
        d.setData_hora_s(Calendar.getInstance());
        
       despacheRep.save(d);
    }

}

Can anybody help me ? Any help is welcome, thank you!

accastell
  • 11
  • 1
  • 3

1 Answers1

0

When you write custom methods in Jpa Repository, spring tries to implement automaticaly some of them if it can. During that phase Spring checks the name of the method and tries to match the name with entity fields.

So if we have

   @Entity 
   public class MyEntity {

    private MyField1 myCustomField1
   }

  public class MyField1 {
    private String myString;
  }

If you declare a Jpa Repository for MyEntity you can declare the following methods and spring will understand what you mean and implement them automatically.

 List<MyEntity>  findByMyCustomField1MyString(String val); //Camel Case seperates entity Fields

 or

 List<MyEntity>  findByMyCustomField1_myString(String val); // _ seperates entity fields

So _ works as a field seperator during method name evaluation from spring

What is wrong in your code

In your Despache Entity you have a field with name funcionario_resp. So you have to declare the following method in your repository

 public List<Despache> findByFuncionario_respId(Long funcionario_respId, Pageable page);

As I already explained _ works as field seperator. So spring understands that method name as following:

  1) a field with name funcionario exists
  2) funcionario is a Class that contains a field with name respId

How to fix your code

Refactor the following field

@Entity
public class Despache implements Serializable{
@Valid
    private Funcionario_resp funcionario_resp;

     ....

}

to

@Entity
public class Despache implements Serializable{
@Valid
    private Funcionario_resp funcionarioResp;

     ....

}

Then in your repository refactor the method

public List<Despache> findByFuncionario_respId(Long funcionario_respId, Pageable page);

like this

@Repository
public interface DespacheRepository extends JpaRepository<Despache, Long>{
    
    public List<Despache> findByFuncionarioRespId(Long funcionario_respId, Pageable page);
     ...  
}
Panagiotis Bougioukos
  • 15,955
  • 2
  • 30
  • 47
  • You may want to explain what the problem is and how these changes fixes it? – Thorbjørn Ravn Andersen Apr 03 '21 at 22:23
  • @ThorbjørnRavnAndersen > Your repository can not understand the entity field with a name that contains _ <. I can not explain why spring does not understand it in a single post. Someone must hack inside spring to understand it. But that's the main reason for the problem. I went and fixed that problem on the provided code – Panagiotis Bougioukos Apr 03 '21 at 22:26
  • Yes, "_" was the problem, I removed it and it worked, thank you! – accastell Apr 04 '21 at 05:01