IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

Erreur execution requete


Sujet :

Hibernate Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2007
    Messages
    257
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Décembre 2007
    Messages : 257
    Par défaut Erreur execution requete
    Bonjour,

    J'ai une erreur a l’exécution d'une requête nommée. Voici les classes a priori concernees:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
     
    @Entity
    @Table(name = "TN_TYPE")
    @NamedQueries({
          @NamedQuery(
              name = "TNType.findPubIdTn",
              query = "from TNType")
    })
    public class TNType extends PubIdType implements Serializable {
     
        @Column(nullable=false)
        private String tn;
     
        @Embedded
        private CORInfoType corInfo;
     
        @ElementCollection
        private List<RteRecRefType> rrRef;
     
        public TNType() {
        }
     
        public TNType(String rant, DestGrpType dg, String tn, CORInfoType corInfo, List<RteRecRefType> rrRef) {
            super(rant, dg);
            this.tn = tn;
            this.corInfo = corInfo;
            this.rrRef = rrRef;
        }
     
     
        /**
         * @return the tn
         */
        public String getTn() {
            return tn;
        }
     
        /**
         * @return the corInfo
         */
        public CORInfoType getCorInfo() {
            return corInfo;
        }
     
        /**
         * @return the rrRef
         */
        public List<RteRecRefType> getRrRef() {
            return rrRef;
        }
     
        /**
         * @param corInfo the corInfo to set
         */
        public void setCorInfo(CORInfoType corInfo) {
            this.corInfo = corInfo;
        }
     
        /**
         * @param rrRef the rrRef to set
         */
        public void setRrRef(List<RteRecRefType> rrRef) {
            this.rrRef = rrRef;
        }
    }
     
    @Embeddable
    public class CORInfoType implements Serializable {
     
        private boolean corClaim;
     
        private boolean cor;
     
        @Temporal(TemporalType.TIMESTAMP)
        private Date corDate;
     
     
        public CORInfoType() {
        }
     
        public CORInfoType(boolean corClaim, boolean cor, Date corDate) {
            this.corClaim = corClaim;
            this.cor = cor;
            this.corDate = corDate;
        }
     
     
        /**
         * @return the corClaim
         */
        public boolean isCorClaim() {
            return corClaim;
        }
     
        /**
         * @return the cor
         */
        public boolean isCor() {
            return cor;
        }
     
        /**
         * @return the corDate
         */
        public Date getCorDate() {
            return corDate;
        }
     
        /**
         * @param corClaim the corClaim to set
         */
        public void setCorClaim(boolean corClaim) {
            this.corClaim = corClaim;
        }
     
        /**
         * @param cor the cor to set
         */
        public void setCor(boolean cor) {
            this.cor = cor;
        }
     
        /**
         * @param corDate the corDate to set
         */
        public void setCorDate(Date corDate) {
            this.corDate = corDate;
        }
    }
    Lorsque j'execute ce code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Query query = em.createNamedQuery("TNType.findPubIdTn");
    List<TNType> result = query.getResultList();
    J'obtiens une erreur:
    Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:255)
    at DataAccess.DataAccess.getPubIdTN(DataAccess.java:219)
    at DataAccess.DataAccess.createPubIdTN(DataAccess.java:257)
    at TestClass.main(TestClass.java:27)
    Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.loader.Loader.doList(Loader.java:2536)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)
    ... 3 more
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'tntype0_.cor' in 'field list'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    at com.mysql.jdbc.Util.getInstance(Util.java:382)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3603)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3535)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1989)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2150)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2281)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
    at org.hibernate.loader.Loader.doQuery(Loader.java:802)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.doList(Loader.java:2533)
    ... 11 more
    Java Result: 1
    J'utilise Hibernate et MySQL.

    Merci d'avance

  2. #2
    Membre très actif
    Profil pro
    Inscrit en
    Février 2010
    Messages
    767
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 767
    Par défaut
    L'erreur est écrite dans la pile : com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Unknown column 'tntype0_.cor' in 'field list'

  3. #3
    Membre éclairé
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2007
    Messages
    257
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Décembre 2007
    Messages : 257
    Par défaut
    Merci de la réponse.

    Apparemment l'erreur apparaît par rapport a n'importe quel champs de CORInfoType(cor, corClaim ou corDate). Ça a l'air d’être en rapport avec le fait que c'est un component et non une entité. J'ai essaye ce genre de requête dans la même application pour une entité et je n'obtiens pas cette erreur.

    J'ai récupéré le code SQL de la requête:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    select tntype0_.id as id0_, tntype0_2_.cDate as cDate0_, tntype0_2_.mDate as mDate0_, tntype0_2_.rant as rant0_, tntype0_1_.destGrp_id as destGrp2_6_, tntype0_.cor as cor14_, tntype0_.corClaim as corClaim14_, tntype0_.corDate as corDate14_, tntype0_.tn as tn14_ from TN_TYPE tntype0_ inner join PUB_ID_TYPE tntype0_1_ on tntype0_.id=tntype0_1_.id inner join BASIC_OBJ_TYPE tntype0_2_ on tntype0_.id=tntype0_2_.id
    Je comprends l'erreur, en fait, il n'y a pas de jointure qui a été faite avec la table correspondant a CORInfoType et dans le select il fait référence aux colonnes cor, corClaim et corDate.
    Mais au départ ma requête HQL c'est : "from TNType". Donc je demande a récupérer toutes les lignes de la table correspondant a TNType. Je reçois donc une instance pour chaque ligne. Et pour chaque instance, il y a le champs de type CORInfoType, pourquoi Hibernate ne me le récupère automatiquement?

Discussions similaires

  1. Erreur d'execution requete HQL avec constructeur
    Par Colonel-Essaid dans le forum Développement Web en Java
    Réponses: 1
    Dernier message: 13/05/2013, 12h02
  2. Erreur execution requete LINQ
    Par bob633 dans le forum Linq
    Réponses: 2
    Dernier message: 24/10/2011, 15h47
  3. Execution requete MAJ = non / Erreur
    Par rjcab dans le forum VBA Access
    Réponses: 2
    Dernier message: 30/06/2008, 16h56
  4. erreur sur execution requete
    Par choubak dans le forum Requêtes et SQL.
    Réponses: 3
    Dernier message: 14/05/2007, 11h42
  5. probleme de requetes VBA/ACESS. erreur execution 3251
    Par schwinny dans le forum Access
    Réponses: 9
    Dernier message: 05/07/2006, 10h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo