JPA criteria builder mit mehreren Verknüpfungen

ich bin kämpfen, um erstellen Sie eine jpa query, macht die Verwendung von mehreren Tabellen. ich kann nicht scheinen zu verstehen, wie Sie join der Tabellen zusammen. dies ist die Abfrage, die ich versuche zu erstellen:

SELECT algm.m_l_i, algnsm.n_s_i
  FROM algm, alg, algnsm, mal
 WHERE algm.l_g_i = alg.l_g_i
   AND alg.l_g_t = 'xxx'
   AND algnsm.l_g_i = algm.l_g_i
   AND mal.c_l_i = algm.m_l_i
   AND mal.p_l_i = 'yyy';

ich habe versucht, mehrere Ansätze, die aus der Verwendung der join-operator, um mit Hilfe des where-operators auf die Tasten. ich finde nicht genug Informationen, auf die Verknüpfungen auf der net viel helfen. ich stecken sobald ich versuche, an mehr als 1 Tabelle tief. einige Ratschläge oder Tipps würde wirklich nützlich sein.
Dank

CriteriaBuilder b = em.getCriteriaBuilder();
CriteriaQuery<Tuple> q = builder.createTupleQuery();
Root<MAL> malRoot = query.from(MAL.class);
Root<ALGM> algmRoot = query.from(ALGM.class);

//error
algmRoot.join(ML_.mLI);
//error
malRoot.join(ML_.mLI);

Predicate e1 = builder.equal(malRoot.get(MAL_.pL).get(ML_.mLI), "abc");
Predicate e2 = builder.equal(malRoot.get(MAL_.cL), algmRoot.get(ALGM_.mL));

query.where(builder.and(e1, e2));

query.select(builder.tuple(malRoot.get(MAL_.pL), malRoot.get(MAL_.cL), algmRoot.get(ALGM_.aLG).get(ALG_.lGT)));

@Entity
@Table(name = "M_A_L")
public class MAL implements Serializable {
   @EmbeddedId
   protected MALPK malPK;

   @Basic(optional = false)
   @Column(name = "ENTRY_IND")
   private String entryInd;

   @JoinColumn(name = "P_L_I", referencedColumnName = "M_L_I", insertable = false, updatable = false)
   @ManyToOne(optional = false)
   private ML pL;

   @JoinColumn(name = "C_L_I", referencedColumnName = "M_L_I", insertable = false, updatable = false)
   @ManyToOne(optional = false)
   private ML cL;
 ... 
 }

@Entity
@Table(name = "A_L_G_M")
public class ALGM implements Serializable {

    @EmbeddedId
    protected ALGMPK algmPK;

    @JoinColumn(name = "M_L_I", referencedColumnName = "M_L_I", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private ML mL;

    @JoinColumn(name = "L_G_I", referencedColumnName = "L_G_I", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private ALG aLG;
 ....
 }

public class ALGM_ { 
   public static volatile SingularAttribute<ALGM, ML> mL;
   public static volatile SingularAttribute<ALGM, ALGMPK> aLGMPK;
   public static volatile SingularAttribute<ALGM, ALG> aLG;
}

public class MAL_ { 
   public static volatile SingularAttribute<MAL, String> eI;
   public static volatile SingularAttribute<MAL, MALPK> mALPK;
   public static volatile SingularAttribute<MAL, ML> pL;
   public static volatile SingularAttribute<MAL, ML> cL;
}

public class ALG_ { 
   public static volatile CollectionAttribute<ALG, MW> mWC;
   public static volatile SingularAttribute<ALG, ALGCM> aLGCM;
   public static volatile SingularAttribute<ALG, ALGAVM> aLGAVM;
   public static volatile SingularAttribute<ALG, TR> tZ;
   public static volatile CollectionAttribute<ALG, ALGM> aLGMC;
   public static volatile SingularAttribute<ALG, String> d;
   public static volatile SingularAttribute<ALG, String> lGT;
   public static volatile SingularAttribute<ALG, String> lGI;
   public static volatile SingularAttribute<ALG, ALGNSM> aLGNSM;
   public static volatile SingularAttribute<ALG, ALGFVM> aLGFVM;
   public static volatile SingularAttribute<ALG, ALGNAM> aLGNAM;
}
Sie waren in der Lage, eine Lösung zu finden? Wenn dem so ist, kannst du vielleicht hier posten? Dank
Sorry, ich habe nie es vollständig zu arbeiten. Ich verwendet eine andere Technologie am Ende 🙁

InformationsquelleAutor | 2010-10-06

Schreibe einen Kommentar