because this error: Creating bean whith name NameRepository, No property parameters found for type?

0

I have the following service

public List<Factura> listFactura(String campo1, String campo2, String Campo3);

and its implementation

@Autowired
private FacturaRepository repository;

public List<Factura> listFactura(String campo1, String campo2, String campo3){
       return repository.findByParameters(campo1, campo2, campo3);
}

and the Reporsitory

public interface FacturaRepository extends JpaRepository<Factura, Integer>{
   @Query(name="detalleFactura", nativeQuery=true)
public List<Factura> findByParameters(String campo1, String campo2, String campo3);
}

This is my entity

@Entity
@Table(name="FACTURA")
public class Factura implements Serializable{

@Id
@Column(name="ID_FACTURA")
private int idFactura;

@Column(name ="CAMPO1")
private String campo1;

@Column(name ="CAMPO2")
private String campo2;

@Column(name ="CAMPO3")
private String campo3;

//sus get y set

}

and I have an xml file, where the query goes,

<named-native-query name="detalleFactura"
      result-class="mx.com.proyect.entidades.Factura">

SELECT * FROM FACTURA F 
WHERE F.campo1=?1, F.campo2=?2 and F.campo3=?#

</named-native-query>
<sql-result-set-mapping name="mx.com.proyect.entidades.Factura">
<entity-result>
  <field-result name="idFactura" column="ID_FACTURA"/>
  <field-result name="campo1" column="CAMPO1"/>
</entity-result>
</sql-result-set-mapping

but when you lift the application, send me that error What do I need? Something is missing?

Error creating bean with name "InvoiceRepository", No property parameters found for type Invoice

    
asked by Root93 05.06.2018 в 06:08
source

1 answer

1

The problem is the name of the method that you declared in your Repository Invoice.

As Spring + JPA works, when you extend from JpaRepository, Spring applies a convention based on the name of the methods. All those that are "findByXXXX" are processed by Spring and what they find, after the "By", assumes that they are the names of the attributes for which they have to filter. For example, this method:

List<Driver> findByNameAndSurnameAndBirthDateAllIgnoreCase(String name, String surname, LocalDate date);

It tells Spring that it has to find, in the Driver class, all those records whose Name, Surname and BirthDate, ignoring the differences in uppercase or lowercase, match the parameters that you are going through.

In your specific case, the exception says:

No property parameters found for type

That is, Spring warns you that in the Invoice type (because you have declared that the generic type used in your interface is that) there is no attribute that is called parameters Where does that come from? From the name of the findByParameters method.

Solution? Change your repository and leave it like this, for example:

public interface FacturaRepository extends JpaRepository<Factura, Integer>{

    @Query(name="detalleFactura", nativeQuery=true)
    public List<Factura> buscaPorParametros(String campo1, String campo2, String campo3);
}
    
answered by 06.06.2018 / 08:59
source