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

JPA Java Discussion :

java.lang.ClassCastException: gestcom.entities.Structure cannot be cast to gestcom.components.VopD


Sujet :

JPA Java

  1. #1
    Membre régulier
    Inscrit en
    Mai 2003
    Messages
    350
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 350
    Points : 84
    Points
    84
    Par défaut java.lang.ClassCastException: gestcom.entities.Structure cannot be cast to gestcom.components.VopD
    Bonjour, j'ai un petit souci au niveau de la cast.
    je ramène des données d'une requête

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    private java.util.List<gestcom.components.VopD> VopDataList;
    private javax.persistence.Query VopDataQuery;
     
    VopDataQuery = java.beans.Beans.isDesignTime() ? null : gestcomPUEntityManager.createQuery("SELECT o.code,o.libelle,o.objet,o.montant,o.datefin,o.datedeb,o.datesais,o.statut,o.structure,o.nature,e.sens,sum(e.montant) from Operation o ,Ecriture e where o.code = e.operation and e.sens= 'C' group by o.code,o.libelle,o.objet,o.montant,o.datefin,o.datedeb,o.datesais,o.statut,o.structure,o.nature,e.sens");
     
            VopDataList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : structureQuery.getResultList();
    Pour récupérer ses données de la requête j'ai crée une classe
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    public class VopD {
           public Structure  structure;
           public Nature  nature;
           public String  libelle;
           public String  objet;
           public Date    date_deb;
           public Date    date_fin;
           public Long    montant;
           public Long    paye;
        }
    pour gérer l'affichage la classe
    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
     
    public class VopData {
      public static ImageIcon ICON_UP = new ImageIcon("ArrUp.gif");
      public static ImageIcon ICON_DOWN = new ImageIcon("ArrDown.gif");
      public static ImageIcon ICON_BLANK = new ImageIcon("blank.gif");
     
      private IconData  structure;
      private Integer   nature;
      private String    libelle;
      private String    objet;
      private Date      date_deb;
      private Date      date_fin;
      private SmartLong montant;
      private SmartLong paye;
      private float     progress;
     
      public VopData(Structure structure,
                     Nature nature,
                     String libelle,
                     String objet,
                     Date date_deb,
                     Date date_fin,
                     Long montant,
                     Long paye){
    	 this.structure = new IconData(getIcon(montant,paye), structure.getCode());
    	 this.nature    = nature.getCode();
             this.libelle = libelle;
    	 this.objet = objet;
             this.date_deb = date_deb;
    	 this.date_fin = date_fin;
             this.montant = new SmartLong(montant);
    	 this.nature = nature.getCode();
             this.paye = new SmartLong(paye);
    	 this.progress = (float)((paye/montant) * 100);
      }
     
      public static ImageIcon getIcon(double change) {
        return (change>0 ? ICON_UP : (change<0 ? ICON_DOWN :
          ICON_BLANK));
      }
      public static ImageIcon getIcon(Long m1, Long m2) {
        return (m1>m2 ? ICON_UP : (m1<=m2 ? ICON_DOWN :
          ICON_BLANK));
      }
     
      public String getStructure() { return structure.toString(); }
      public Integer getNature() { return nature; }
      public String getLibelle() { return libelle; }
      public String getObjet() { return objet; }
      public Date getDatedeb() { return date_deb; }
      public Date getDatefin() { return date_fin; }
      public Long getMontant() { return montant.longValue(); }
      public Long getPaye() { return paye.longValue(); }
      public float getProgress() { return progress; }
      public String toString(){ return "[ pourcentage de réalisation : " + this.progress + "% ]";}
    }
    Dans ma classe model pour la correspondance des données je fais:
    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
     
    public VopModel(java.util.List<gestcom.components.VopD>dataList){
          setData(dataList);
      }
     
      public void setData(java.util.List<gestcom.components.VopD> dataList){
          m_frm = new SimpleDateFormat("MM/dd/yyyy");
          model.removeAllElements();
         //Object[] values = dataList.getSelectedValues();
         for (int i = 0; i<dataList.size(); i++) {
            //outputListModel.addElement(values[i]);
            model.addElement(new VopData(dataList.get(i).structure,
                                         dataList.get(i).nature,
                                         dataList.get(i).libelle,
                                         dataList.get(i).objet,
                                         dataList.get(i).date_deb,
                                         dataList.get(i).date_fin,
                                         dataList.get(i).montant,
                                         dataList.get(i).paye));
         }
         // the table model is interested in changes of the rows
         fireTableRowsInserted(model.size()-1, model.size()-1);
      }
    A l'exécution j'ai l'erreur
    [TopLink Info]: 2009.09.30 07:50:56.515--ServerSession(13419912)--TopLink, version: Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))
    [TopLink Info]: 2009.09.30 07:50:56.937--ServerSession(13419912)--file:/C:/workspace/Netbeans/Gestcom/build/classes/-gestcomPU login successful
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: gestcom.entities.Structure cannot be cast to gestcom.components.VopD
    at gestcom.components.VopModel.setData(VopModel.java:90)
    at gestcom.components.VopModel.<init>(VopModel.java:81)
    at gestcom.view.F_CE_Operation.initComponents(F_CE_Operation.java:65)
    at gestcom.view.F_CE_Operation.<init>(F_CE_Operation.java:25)
    at gestcom.view.F_CE_Operation$1.run(F_CE_Operation.java:144)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    BUILD SUCCESSFUL (total time: 2 seconds)
    qui pointe dans la classe model sur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    model.addElement(new VopData(dataList.get(i).structure,
                                         dataList.get(i).nature,
                                         dataList.get(i).libelle,
                                         dataList.get(i).objet,
                                         dataList.get(i).date_deb,
                                         dataList.get(i).date_fin,
                                         dataList.get(i).montant,
                                         dataList.get(i).paye));
    je ne vois pas pourquoi alors je sollicite votre aide

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Points : 48 807
    Points
    48 807
    Par défaut
    dataList contient des "gestcom.entities.Structure" alors que tu as déclaré qu'il contenait des "gestcom.components.VopD". C'est probablement le code en gestcom.view.F_CE_Operation.initComponents(F_CE_Operation.java:65) qui est erroné et passe une mauvaise liste à new VopModel().

  3. #3
    Membre régulier
    Inscrit en
    Mai 2003
    Messages
    350
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 350
    Points : 84
    Points
    84
    Par défaut
    merci j'ai rorrigé cette erreur mais il n'accepte cependant pas la requête alors que quand je la teste en ligne de commande ça marche
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    VopDataQuery = java.beans.Beans.isDesignTime() ? null : gestcomPUEntityManager.createQuery("select o.code,o.libelle,o.objet,o.montant,o.datefin,o.datedeb,o.datesais,o.statut,o.structure,o.nature,e.sens,sum(e.montant) from Operation o ,Ecriture e where o.code = e.operation and e.sens= 'C' group by o.code,o.libelle,o.objet,o.montant,o.datefin,o.datedeb,o.datesais,o.statut,o.structure,o.nature,e.sens");
    erreur
    Query: ReportQuery(gestcom.entities.Operation)
    Exception in thread "AWT-EventQueue-0" Local Exception Stack:
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND (t1.SENS = 'C')) AND (t2.CODE = t1.OPERATION)) GROUP BY t0.CODE, t0.LIBELL' at line 1
    Error Code: 1064
    Call: SELECT t0.CODE, t0.LIBELLE, t0.OBJET, t0.MONTANT, t0.DATEFIN, t0.DATEDEB, t0.DATESAIS, t0.STATUT, t0.STRUCTURE, t0.NATURE, t1.SENS, SUM(t1.MONTANT) FROM gestcom.operation t0, gestcom.operation t2, gestcom.ecriture t1 WHERE (((t0.CODE = ) AND (t1.SENS = ?)) AND (t2.CODE = t1.OPERATION)) GROUP BY t0.CODE, t0.LIBELLE, t0.OBJET, t0.MONTANT, t0.DATEFIN, t0.DATEDEB, t0.DATESAIS, t0.STATUT, t0.STRUCTURE, t0.NATURE, t1.SENS
    bind => [C]
    Query: ReportQuery(gestcom.entities.Operation)
    at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:319)
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:566)
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:452)
    at oracle.toplink.essentials.threetier.ServerSession.executeCall(ServerSession.java:473)
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:214)
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:285)
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:615)
    at oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2416)
    at oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.selectAllReportQueryRows(ExpressionQueryMechanism.java:2382)
    at oracle.toplink.essentials.queryframework.ReportQuery.executeDatabaseQuery(ReportQuery.java:802)
    at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:628)
    at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:692)
    at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:746)
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2233)
    at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:952)
    at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:924)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:367)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.getResultList(EJBQueryImpl.java:478)
    at gestcom.view.F_CE_Operation.initComponents(F_CE_Operation.java:54)
    at gestcom.view.F_CE_Operation.<init>(F_CE_Operation.java:25)
    at gestcom.view.F_CE_Operation$1.run(F_CE_Operation.java:144)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND (t1.SENS = 'C')) AND (t2.CODE = t1.OPERATION)) GROUP BY t0.CODE, t0.LIBELL' at line 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1403)
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:726)
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:501)
    ... 28 more
    BUILD SUCCESSFUL (total time: 3 seconds)
    j'ai aussi essayé le code produit par MySQL en reportant le code generé après création de la vue mais ça ne marche toujours pas.
    Je croyais que l'api ne tenait pas compte du type de SGDB (mysql,oracle, etc..)

  4. #4
    Membre régulier
    Inscrit en
    Mai 2003
    Messages
    350
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 350
    Points : 84
    Points
    84
    Par défaut
    ok le problème est résolu
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    VopDataQuery = java.beans.Beans.isDesignTime() ? null : gestcomPUEntityManager.createQuery("select o.code,o.libelle,o.objet,o.montant,o.datefin,o.datedeb,o.datesais,o.statut,o.structure,o.nature,e.sens,sum(e.montant) from Operation o, Ecriture e where o.code = e.operation.code and e.sens = 'C' group by o.code,o.libelle,o.objet,o.montant,o.datefin,o.datedeb,o.datesais,o.statut,o.structure,o.nature,e.sens");

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 7
    Dernier message: 20/01/2015, 10h33
  2. Réponses: 2
    Dernier message: 24/05/2011, 10h16
  3. java.lang.ClassCastException: $Proxy2 cannot be cast
    Par olivier57b dans le forum Java EE
    Réponses: 0
    Dernier message: 14/07/2010, 20h52
  4. Réponses: 1
    Dernier message: 26/04/2010, 11h03
  5. Réponses: 1
    Dernier message: 02/10/2009, 16h49

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