2015-08-05 27 views
5

ModelB'deki kullanıcı modelA tabanından veri almak istiyorum. Ama zorunlu değil, her kayıt için modelB'de rekor sahibi olacağım. Veriyi almak için kodun altını kullandığımda, 0 kayıt döndürüyor. i hata ayıklamaSorgu sorguları oluştururken çapraz birleştirme QueryDSL

BooleanExpression searchCriteria = searchCriteria 
      .and(
        qModelA.modelb.user.id.eq(userId) 
      ) 
      .and (some other conditions as well); 

modelA.findAll(searchCriteria, pageable); 

i QueryDsl Çapraz katılmak koymak bulundu. Bunu nasıl düzeltebileceğimi söyleyen herkes, çapraz katılma yerine sol eklemeyi ekleyen sorgudsl'ın herhangi bir yolu var mı? aşağıda benim iki modelim.

@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; 
    } 

} 
+1

nasıl bunu düzeltmek nasıl başardınız? –

cevap

0

bir sol yerine katılmak gerekiyorsa açık kullanmanız gerekecektir katılır:

query.from(modelA) 
    .leftJoin(modelA.modelB, modelB) 
    ... 
+0

Ancak sorun, bu findAll yöntemiyle kullanılamaz. –

+0

Bir yüklem yalnızca bir filtre koşuludur, bununla başka bir şey ifade edemezsiniz. –

+1

Bunu nasıl düzelttiniz? –

İlgili konular