0

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);
}
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
Nikki Singh
  • 43
  • 2
  • 5

2 Answers2

1
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);
}
codiallo
  • 173
  • 4
  • hello codiallo i like your solution...and i m a newbie in stackoverflow...so how do i provide value to #entityName..and thanks for this answer for my first stackoverflow question. – Nikki Singh Jun 12 '19 at 10:16
  • PROBLEM!!!! ITS THROWING "NOT A MANAGED TYPE 'T' ENTITY CANT CREATE BEAN OF PersoRepo" .what should i do now? – Nikki Singh Jun 12 '19 at 10:39
  • You does not need to set entity name. Can I see your source code where you use the repository ? – codiallo Jun 14 '19 at 05:58
0

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.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • hello thanks for this answer..can u please explain me whats this duplicate of this question means i m unable to get it. and i knowsome basics of criteria api. – Nikki Singh Jun 12 '19 at 10:20
  • It means it is basically the same question and you should read the answers to the linked question. – Jens Schauder Jun 12 '19 at 10:40