java - JPQL query in Spring data jpa -


lets have :

class range {   public long start;   public long end; } 

this jpa entity:

@entity @table(name="entry") public class entry {   @id   long id;    @onetomany   set<individual> individuals; } 

another jpa entity:

@entity @table(name="individual") public class individual {   @id   long id;    long code;    @manytoone   entry entry; } 

and controller:

public class indexedentrycontroller {   entitymanagerfactory emf;    list<entry> find(list<range> lst) {     string str = "";      for(range r:lst) {       if(!str.isempty) {         str += " or ";       }       str += "(i.code between " + r.start + " , " + r.end + ")";     }      string query = "select i.entry individual " + str + " group i.entry having count(i) > " + lst.size()-1;     entitymanager em = emf.createentitymanager();      return em.createquery(query).getresultlist();   } } 

this query returns entries have n-1 individuals code between 1 of specific ranges, n number of ranges.

i want move spring jparepository. how can implement query jparepository?


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -