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 :

Récupérer des informations à partir d'un select avec hibernate


Sujet :

Hibernate Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    172
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 172
    Points : 60
    Points
    60
    Par défaut Récupérer des informations à partir d'un select avec hibernate
    Bonjour tout le monde,
    J'apprend à partir d'un tutoriel hibernate créé par julien DEFAUT.

    Je suis à la dernière parti du tutoriel mais lorsque je compile, il me génére des erreurs les voici:
    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
    INFO: Hibernate 2.1.6
    3 avr. 2007 15:02:10 net.sf.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    3 avr. 2007 15:02:10 net.sf.hibernate.cfg.Environment <clinit>
    INFO: using CGLIB reflection optimizer
    3 avr. 2007 15:02:10 net.sf.hibernate.cfg.Configuration configure
    INFO: configuring from resource: /hibernate.cfg.xml
    3 avr. 2007 15:02:10 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: Configuration resource: /hibernate.cfg.xml
    3 avr. 2007 15:02:10 net.sf.hibernate.cfg.Configuration addResource
    INFO: Mapping resource: TContact.hbm.xml
    3 avr. 2007 15:02:13 net.sf.hibernate.cfg.Binder bindRootClass
    INFO: Mapping class: com.minosis.hibernate.TContact -> t_contact
    3 avr. 2007 15:02:14 net.sf.hibernate.cfg.Configuration doConfigure
    INFO: Configured SessionFactory: null
    3 avr. 2007 15:02:14 net.sf.hibernate.cfg.Configuration secondPassCompile
    INFO: processing one-to-many association mappings
    3 avr. 2007 15:02:14 net.sf.hibernate.cfg.Configuration secondPassCompile
    INFO: processing one-to-one association property references
    3 avr. 2007 15:02:14 net.sf.hibernate.cfg.Configuration secondPassCompile
    INFO: processing foreign key constraints
    3 avr. 2007 15:02:14 net.sf.hibernate.cfg.SettingsFactory buildSettings
    ATTENTION: No dialect set - using GenericDialect: Dialect class not found: org.hibernate.dialect.MySQLDialect
    3 avr. 2007 15:02:14 net.sf.hibernate.dialect.Dialect <init>
    INFO: Using dialect: net.sf.hibernate.dialect.GenericDialect
    3 avr. 2007 15:02:14 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Use outer join fetching: true
    3 avr. 2007 15:02:14 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Using Hibernate built-in connection pool (not for production use!)
    3 avr. 2007 15:02:14 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Hibernate connection pool size: 20
    3 avr. 2007 15:02:14 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost/base1
    3 avr. 2007 15:02:14 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: connection properties: {user=root}
    3 avr. 2007 15:02:14 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
    INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
    3 avr. 2007 15:02:14 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Use scrollable result sets: true
    3 avr. 2007 15:02:14 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Use JDBC3 getGeneratedKeys(): true
    3 avr. 2007 15:02:14 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Optimize cache for minimal puts: false
    3 avr. 2007 15:02:14 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query language substitutions: {}
    3 avr. 2007 15:02:14 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
    3 avr. 2007 15:02:14 net.sf.hibernate.cfg.Configuration configureCaches
    INFO: instantiating and configuring caches
    3 avr. 2007 15:02:14 net.sf.hibernate.impl.SessionFactoryImpl <init>
    INFO: building session factory
    3 avr. 2007 15:02:15 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
    INFO: Not binding factory to JNDI, no JNDI name configured
    Exception in thread "main" net.sf.hibernate.QueryException: * only allowed inside aggregate function in SELECT [SELECT * FROM t_contact WHERE nom='Dupont']
    	at net.sf.hibernate.hql.SelectParser.token(SelectParser.java:114)
    	at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
    	at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:114)
    	at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143)
    	at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
    	at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
    	at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
    	at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:294)
    	at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1562)
    	at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1533)
    	at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1521)
    	at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1513)
    	at Test.main(Test.java:20)
    .


    Je vous donne le code que je génére le voici:
    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
     
     
     
     
     
    import java.util.Iterator;
    import java.util.Vector;
     
    import net.sf.hibernate.*;
     
     
     
    import com.minosis.hibernate.*;
    import com.minosis.bdd.*;
    public class Test {
     
    public static void main(String[] args) throws HibernateException
    {
    	Session session=(Session)HibernateUtil.currentSession();
    	Iterator list=(Iterator)session.find("SELECT * FROM t_contact WHERE nom like '%t'");
    	while(list.hasNext())
    	{
    		TContact contact=(TContact) list.next();
    		System.out.println(contact.getNom());
    	}
    	HibernateUtil.closeSession();
     
     
    }
    }
    Les informations qui sont rentrées dans la base de données correspondant à la requete de sélection n'apparait pas.
    Je vous remercie de votre aide

  2. #2
    Membre à l'essai
    Inscrit en
    Avril 2007
    Messages
    18
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 18
    Points : 16
    Points
    16
    Par défaut
    Bonjour Gentil,

    Je suis débutant sur Hibernate, mais à priori il n'aime pas ton "select *"...

    Par contre tu pourrais essayer de remplacer

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Iterator list=(Iterator)session.find("SELECT * FROM t_contact WHERE nom like '%t'");
    par

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Iterator list=(Iterator)session.createQuery("FROM t_contact WHERE nom like '%t'").list();
    Par contre je pensais à autre chose, "t_contact" correspond bien au nom de ta classe dans ton fichier de mapping hibernate et non au nom de ta table dans ta base?

    J'ai un programme plus ou moins similaire au tiens, et de cette manière, j'arrive à récupérer une liste d'utilisateur.

    Tiens nous au courant de l'avancée des choses!

  3. #3
    Membre chevronné
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2007
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 348
    Points : 1 787
    Points
    1 787
    Par défaut
    Pas très HQL ta requête ...
    Effectivement, soit tu ne mets pas le select, soit tu fais qqchose du genre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    SELECT contact FROM t_contact contact WHERE nom like '%t'
    Et effectivement, t_contact si c'est le nom de ta classe c'est très bof bof

  4. #4
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 166
    Points
    4 166
    Par défaut
    ATTENTION: No dialect set - using GenericDialect: Dialect class not found: org.hibernate.dialect.MySQLDialect
    Vérifie le nom de ton dialect, car celui-ci n'a pas l'air de lui plaire.

Discussions similaires

  1. Récupérer des informations à partir d'une adresse IP
    Par bobbely dans le forum Développement
    Réponses: 5
    Dernier message: 23/02/2012, 12h05
  2. récupérer des informations à partir une table
    Par chaima01 dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 09/06/2011, 23h05
  3. Réponses: 3
    Dernier message: 21/03/2009, 23h24
  4. Réponses: 2
    Dernier message: 12/06/2008, 11h48
  5. [SNMP] récupérer des informations de la MIB avec un script snmp
    Par patchiko dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 27/06/2007, 12h05

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