0

私のツアー ("tournee") に基づいて、クラスのトーナメント (profil_tournee) リストで自分のプロファイルを取得したいと考えています。ただし、私には例外があります。誰でも私を助けることができますか?

スレッド「AWT-EventQueue-0」の例外 java.lang.IllegalArgumentException: TypedQuery に指定された型 [fr.galettedebroons.domain.Profil] は、クエリの戻り値の型 [interface java.util.Collection] と互換性がありません

リクエスト:

 List<List<Profil>> listProfil = Arrays.asList(manager_.createQuery("select t.profil_tournee "
            + "FROM Tournee t WHERE t.nom LIKE :tournee", Profil.class)
            .setParameter("tournee", tournee)
            .getResultList());

モデル :

@Entity
public class Tournee {
    private int id;
    private String nom;
    private boolean lundi = false;
    private boolean mardi = false;
    private boolean mercredi = false;
    private boolean jeudi = false;
    private boolean vendredi = false;
    private boolean samedi = false;
    private boolean dimanche = false;
    private List<Profil> profil_tournee;

    public Tournee(){}

    public Tournee(String nom, boolean lundi, boolean mardi, boolean mercredi, boolean jeudi,
            boolean vendredi, boolean samedi, boolean dimanche, List<Profil> profil_tournee) {
        this.nom = nom;
        this.lundi = lundi;
        this.mardi = mardi;
        this.mercredi = mercredi;
        this.jeudi = jeudi;
        this.vendredi = vendredi;
        this.samedi = samedi;
        this.dimanche = dimanche;
        this.profil_tournee = profil_tournee;
    }

    public Tournee(String nom, boolean lundi, boolean mardi, boolean mercredi, boolean jeudi,
            boolean vendredi, boolean samedi, boolean dimanche) {
        this.nom = nom;
        this.lundi = lundi;
        this.mardi = mardi;
        this.mercredi = mercredi;
        this.jeudi = jeudi;
        this.vendredi = vendredi;
        this.samedi = samedi;
        this.dimanche = dimanche;
    }

    @Id @GeneratedValue(strategy = GenerationType.AUTO)
    public int getId() {
        return id;
    }

    public void setId(int id_tournee) {
        this.id = id_tournee;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public boolean isLundi() {
        return lundi;
    }

    public void setLundi(boolean lundi) {
        this.lundi = lundi;
    }

    public boolean isMardi() {
        return mardi;
    }

    public void setMardi(boolean mardi) {
        this.mardi = mardi;
    }

    public boolean isMercredi() {
        return mercredi;
    }

    public void setMercredi(boolean mercredi) {
        this.mercredi = mercredi;
    }

    public boolean isJeudi() {
        return jeudi;
    }

    public void setJeudi(boolean jeudi) {
        this.jeudi = jeudi;
    }

    public boolean isVendredi() {
        return vendredi;
    }

    public void setVendredi(boolean vendredi) {
        this.vendredi = vendredi;
    }

    public boolean isSamedi() {
        return samedi;
    }

    public void setSamedi(boolean samedi) {
        this.samedi = samedi;
    }

    public boolean isDimanche() {
        return dimanche;
    }

    public void setDimanche(boolean dimanche) {
        this.dimanche = dimanche;
    }

    @OneToMany(mappedBy="profil_tournee", cascade=CascadeType.PERSIST)
    public List<Profil> getProfil_tournee() {
        return profil_tournee;
    }

    public void setProfil_tournee(List<Profil> profil_tournee) {
        this.profil_tournee = profil_tournee;
    }
}
@Entity
public class Profil {
    private String code_client;
    private Client client_profil;
    private Gamme gamme_profil;
    private List<Livraison> livraison_profil;
    private Boolean actif;
    private Tournee profil_tournee;
    private List<MargeLivraison> marge_profil;
    private List<Prevision> prevision_profil;

    public Profil(){}

    public Profil(Gamme code_gamme, List<Livraison> livraison, Boolean actif) {
        this.gamme_profil = code_gamme;
        this.livraison_profil = livraison;
        this.actif = actif;
    }

    @Id
    public String getCode_client() {
        return code_client;
    }

    public void setCode_client(String code_client) {
        this.code_client = code_client;
    }

    public Boolean getActif() {
        return actif;
    }

    public void setActif(Boolean actif) {
        this.actif = actif;
    }

    @ManyToOne
    public Gamme getGamme_profil() {
        return gamme_profil;
    }

    public void setGamme_profil(Gamme gamme_profil) {
        this.gamme_profil = gamme_profil;
    }

    @OneToMany(mappedBy="livraison_profil", cascade=CascadeType.PERSIST)
    public List<Livraison> getLivraison_profil() {
        return livraison_profil;
    }

    public void setLivraison_profil(List<Livraison> livraison_profil) {
        this.livraison_profil = livraison_profil;
    }

    @ManyToOne
    public Client getClient_profil() {
        return client_profil;
    }

    public void setClient_profil(Client client) {
        this.client_profil = client;
    }

    @ManyToOne
    public Tournee getProfil_tournee() {
        return profil_tournee;
    }

    public void setProfil_tournee(Tournee profil_tournee) {
        this.profil_tournee = profil_tournee;
    }

    @OneToMany(mappedBy="marge_profil", cascade=CascadeType.PERSIST)
    public List<MargeLivraison> getMarge_profil() {
        return marge_profil;
    }

    public void setMarge_profil(List<MargeLivraison> marge_profil) {
        this.marge_profil = marge_profil;
    }

    @OneToMany(mappedBy="prevision_profil", cascade=CascadeType.PERSIST)
    public List<Prevision> getPrevision_profil() {
        return prevision_profil;
    }

    public void setPrevision_profil(List<Prevision> prevision_profil) {
        this.prevision_profil = prevision_profil;
    }
4

2 に答える 2

0

あなたのエラーは、メソッドを呼び出すときに戻り値の型が宣言された型と一致している必要があるというヒントを与えてくれますEntityManager.createQuery(query, Type):

List<SomeType> em.createQuery("SELECT s FROM SomeType", SomeType.class);

ただし、実際の問題は、クエリが違法であることです。JPA では、コレクション値式を SELECT 句の一部にすることはできません。私の別の回答をご覧ください https://stackoverflow.com/a/25890863/3796586

あなたの場合の解決策は、次のようにクエリを逆にすることです。

List<Profil> result = em.createQuery("SELECT p FROM Profil p WHERE" +
    "p.profil_tournee.norm LIKE :tournee", Profil.class)
        .setParameter("tournee", tournee)
        .getResultList());
于 2015-03-28T12:25:38.000 に答える
0

期待される結果リストには、プロファイルではなく、プロファイルのリストである要素が含まれます。

クエリの作成のために、Profil.class を List.class に置き換えます。

List<List<Profil>> listProfil = Arrays.asList(manager_.createQuery("select t.profil_tournee "
        + "FROM Tournee t WHERE t.nom LIKE :tournee", List.class)
        .setParameter("tournee", tournee)
        .getResultList());
于 2015-03-27T14:56:09.200 に答える