java - QueryDSL add cross join when building predicate queries -


i want fetch data modela base on user in modelb. not compulsory every record have record in modelb. when use below code fetch data, return 0 records.

booleanexpression searchcriteria = searchcriteria           .and(                    qmodela.modelb.user.id.eq(userid)               )           .and ( other conditions well);  modela.findall(searchcriteria, pageable); 

when debug found querydsl put cross join. can tell me how fix this, there way querydsl add left join instead of cross join? below 2 models.

@entity public class modela implements serializable {      private long id;     private string label;     private modelb modelb;      @id     @sequencegenerator(name = "modelaseq", sequencename = "modela_id_seq", allocationsize = 1)     @generatedvalue(strategy = generationtype.sequence, generator = "modelaseq")     public long getid() {         return id;     }      public void setid(long id) {         this.id = id;     }      @column(length = 150, nullable = false)     public string getlabel() {         return label;     }      public void setlabel(string label) {         this.label = label;     }      @onetoone(mappedby = "modela", cascade = cascadetype.remove)     public modelb getmodelb() {         return modelb;     }      public void setmodelb(modelb modelb) {         this.modelb = modelb;     }  }  @entity public class modelb implements serializable {      private long id;     private user user;     private modela modela;      @id     @sequencegenerator(name = "modelbseq", sequencename = "modelb_id_seq", allocationsize = 1)     @generatedvalue(strategy = generationtype.sequence, generator = "modelbseq")     public long getid() {         return id;     }      public void setid(long id) {         this.id = id;     }      @notnull     @manytoone     @joincolumn(name = "user_id", nullable = false )     public user getuser() {         return user;     }      public void setuser(user user) {         this.user = user;     }      @notnull     @onetoone     @joincolumn(name = "modela_id", nullable = false)     public modela getmodela() {         return modela;     }      public void setmodela(modela modela) {         this.modela = modela;     }  } 

if need left join instead need use explicit joins:

query.from(modela)      .leftjoin(modela.modelb, modelb)      ... 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -