将多联接的本机查询映射到SqlResultSetMapping

时间:2018-08-02 23:14:20

标签: sql java-ee ejb pojo sqlresultsetmapping

萨拉姆大家

我正在处理一个本机请求的结果,该请求连接了多个表,以便根据作为该行业的标准来检索具有其资格的人员列表。 这是我的本机查询:

myList = em.createNativeQuery("SELECT e.cin, e.nom, e.prenom, q.note1, q.note2, q.diplome, f.intitule AS IntituleFiliere  FROM  t_etudiant AS e INNER JOIN t_choix AS c  ON e.id_etudiant = c.id_etudiant  INNER JOIN t_qualification AS q ON e.id_etudiant = q.etudiant  INNER JOIN t_filiere AS f ON c.id_filiere = f.id_filiere  Where f.intitule = '" + intitule + "' and (q.diplome = 'Licence fondamentale' or q.diplome = 'Licence professionnelle');", Students.class).getResultList();

我在sql模式下的查询是可操作的,当我检索它以这种方式将其分配给List时:

preinscrit = em.createNativeQuery("SELECT e.cin, e.nom, f.intitule as IntituleFiliere  FROM  t_etudiant AS e INNER JOIN t_choix AS c ON e.id_etudiant = c.id_etudiant  INNER JOIN t_filiere AS f ON c.id_filiere = f.id_filiere Where f.intitule = '" + intitule + "';").getResultList();

System.out.println(“罚款!!!”);

它可以正常工作,并且可以按以下方式在表中显示数据:

<p:dataTable value="#{personController.maliste}" var="liste">
    <p:columns value="#{personController.maliste[0]}" columnIndexVar="i" var="column" field="#{column.property}" >
                 <h:outputText value="#{liste[i]}" />
    </p:columns>
</p:dataTable>

想要改进我的方法,我想恢复结果并将其分配给以这种方式定义的POJO:

@SqlResultSetMapping(name = "Students",
        entities = {
            @EntityResult(
                    entityClass = Etudiant.class,
                    fields = {
                        @FieldResult(name = "id", column = "id_etudiant"),
                        @FieldResult(name = "cin", column = "cin"),
                        @FieldResult(name = "cne", column = "cne"),
                        @FieldResult(name = "nom", column = "nom"),
                        @FieldResult(name = "nomAr", column = "nom_ar"),
                        @FieldResult(name = "prenom", column = "prenom"),
                        @FieldResult(name = "prenom_ar", column = "prenom_ar"),
                        @FieldResult(name = "date_naissance", column = "date_naissance")
                        }),
            @EntityResult(
                    entityClass = Qualification.class,
                    fields = {
                        @FieldResult(name = "diplome", column = "diplome"),
                        @FieldResult(name = "mention", column = "mention"),
                        @FieldResult(name = "note1", column = "note1"),
                        @FieldResult(name = "note2", column = "note2"),
                        @FieldResult(name = "note3", column = "note3"),
                        @FieldResult(name = "note4", column = "note4"),
                        @FieldResult(name = "note5", column = "note5"),
                        @FieldResult(name = "note6", column = "note6"),
                        @FieldResult(name = "partie_delivrante", column = "partie_delivrante")})})
public class Students implements Serializable{
    private String cin;
    private Integer cne;
    private String nom;
    private String prenom;
    private String nomAr;
    private String prenomAr;
    private Date dateNaissance;
    private String diplome;
    private long note1;
    private long note2;
    private long note3;
    private long note4;
    private long note5;
    private long note6;
    private String partiedelivrante;

constructor getters and setters and toString Method;

我执行以下操作,我不想持久保存此POJO数据库,我发现自己陷于困境,并且正在寻找建议,如果有人已经进行了这样的操作,并且对多个实体使用了@SqlResultSetMapping注释

0 个答案:

没有答案