Nikki Singh
Nikki Singh

Reputation: 43

How to create one crudrepository for multiple entity and multiple @query in single repo

I want something just like this...i know someone will get it what i want

public interface PersonneRepo extends JpaRepository<T, Long> {

    @Query("Select p.name, p.surname, p.age, p.city, p.street from "+T+" p where p.nom = ?1 and p.prenom = ?2")
    public T customRequest(String nom, String prenom,String T);
}

Upvotes: 0

Views: 4516

Answers (2)

codiallo
codiallo

Reputation: 183

public interface PersoRepo<T> extends JpaRepository<T, Long> {

    @Query("Select p.name, p.surname, p.age, p.city, p.street from  #{#entityName} p where p.nom = :nom and p.prenom = :prenom")
    public T customRequest(@Param("nom") String nom, @Param("prenom") String prenom);
}

Upvotes: 1

Jens Schauder
Jens Schauder

Reputation: 81882

This are three questions:

  1. How to make a repository with a dynamic type parameter

  2. How to make a query with dynamic from clause.

  3. How to make a query method with dynamic return type.

The last you can do with dynamic projections but it will only convert/wrap the result in a proxy of the desired type so that most likely won't really help you.

Number 2 you can do by writing a custom method implementation using the Criteria API.

Number 1 is a duplicate of this question.

Upvotes: 0

Related Questions