1
resposta

Erro compilação: No property findbyNome found for type Curso

Nao consegui entender o erro abaixo na compilacao.

Minha classe CursoRepository esta assim

package br.com.alura.forum.controller.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import br.com.alura.forum.modelo.Curso;

//necessario herdar JPArepository passando generico (entidade, tipo)
public interface CursoRepository extends JpaRepository<Curso, Long> {

    Curso findbyNome(String nomeCurso);

}

Minha classe Curso está assim

package br.com.alura.forum.modelo;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity

public class Curso {

    @Id @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Long id;
    private String nome;
    private String categoria;

    /*
     * desnecessario qdo criamos o esquema do bd
    public Curso(String nome, String categoria) {
        this.nome = nome;
        this.categoria = categoria;
    }*/

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }

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

    public Long getId() {
        return id;
    }

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

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getCategoria() {
        return categoria;
    }

    public void setCategoria(String categoria) {
        this.categoria = categoria;
    }

}

Os erros na compilação foram os seguintes:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cursoRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract br.com.alura.forum.modelo.Curso br.com.alura.forum.controller.repository.CursoRepository.findbyNome(java.lang.String)! No property findbyNome found for type Curso!

Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract br.com.alura.forum.modelo.Curso br.com.alura.forum.controller.repository.CursoRepository.findbyNome(java.lang.String)! No property findbyNome found for type Curso!

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findbyNome found for type Curso!

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cursoRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract br.com.alura.forum.modelo.Curso br.com.alura.forum.controller.repository.CursoRepository.findbyNome(java.lang.String)! No property findbyNome found for type Curso!

Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract br.com.alura.forum.modelo.Curso br.com.alura.forum.controller.repository.CursoRepository.findbyNome(java.lang.String)! No property findbyNome found for type Curso!


Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findbyNome found for type Curso!
1 resposta

O correto é findByNome:

Curso findByNome(String nomeCurso);