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 :

Problème avec hibernate


Sujet :

Hibernate Java

  1. #21
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    145
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 145
    Points : 62
    Points
    62
    Par défaut
    Avec cette sessionFactory j'ai
    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
     
    mars 31, 2016 2:07:05 PM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate Core {5.1.0.Final}
    mars 31, 2016 2:07:05 PM org.hibernate.cfg.Environment <clinit>
    INFO: HHH000206: hibernate.properties not found
    mars 31, 2016 2:07:05 PM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: HHH000021: Bytecode provider name : javassist
    mars 31, 2016 2:07:05 PM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
    WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
    mars 31, 2016 2:07:05 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
    INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
    mars 31, 2016 2:07:05 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
    mars 31, 2016 2:07:05 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/ma_bdd]
    mars 31, 2016 2:07:05 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001001: Connection properties: {user=fnjiokou, password=****}
    mars 31, 2016 2:07:05 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001003: Autocommit mode: false
    mars 31, 2016 2:07:05 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
    INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
    mars 31, 2016 2:07:06 PM org.hibernate.dialect.Dialect <init>
    INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
    mars 31, 2016 2:07:06 PM org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources
    INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@7fecbee0'
    org.hibernate.MappingException: Unknown entity: org.metier.Produit
    	at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:776)
    	at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1533)
    	at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
    	at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
    	at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
    	at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
    	at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
    	at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
    	at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:682)
    	at org.hibernate.internal.SessionImpl.save(SessionImpl.java:674)
    	at org.hibernate.internal.SessionImpl.save(SessionImpl.java:669)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:338)
    	at com.sun.proxy.$Proxy17.save(Unknown Source)
    	at org.metier.CatalogueMetierImpl.addProduit(CatalogueMetierImpl.java:17)
    	at org.metier.TestMetier.main(TestMetier.java:8)
    Exception in thread "main" org.hibernate.SessionException: Session is closed!
    	at org.hibernate.internal.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:132)
    	at org.hibernate.internal.AbstractSessionImpl.getTransaction(AbstractSessionImpl.java:311)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:338)
    	at com.sun.proxy.$Proxy17.getTransaction(Unknown Source)
    	at org.metier.CatalogueMetierImpl.addProduit(CatalogueMetierImpl.java:22)
    	at org.metier.TestMetier.main(TestMetier.java:8)

  2. #22
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    remplacesceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    // loads configuration and mappings
                Configuration configuration = new Configuration().configure();
    avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
      Configuration configuration = new Configuration().addAnnotatedClass(Produit.class).configure();
    Eric

  3. #23
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    145
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 145
    Points : 62
    Points
    62
    Par défaut
    A ce moment la retrouve la, je même erreur que j'avais avant le remplacement de la sessionFactory
    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
     
    mars 31, 2016 4:48:17 PM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate Core {5.1.0.Final}
    mars 31, 2016 4:48:18 PM org.hibernate.cfg.Environment <clinit>
    INFO: HHH000206: hibernate.properties not found
    mars 31, 2016 4:48:18 PM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: HHH000021: Bytecode provider name : javassist
    mars 31, 2016 4:48:18 PM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
    WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
    mars 31, 2016 4:48:18 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
    INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
    mars 31, 2016 4:48:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
    mars 31, 2016 4:48:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/ma_bdd]
    mars 31, 2016 4:48:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001001: Connection properties: {user=fnjiokou, password=****}
    mars 31, 2016 4:48:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001003: Autocommit mode: false
    mars 31, 2016 4:48:18 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
    INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
    mars 31, 2016 4:48:18 PM org.hibernate.dialect.Dialect <init>
    INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
    Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
    	at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:1087)
    	at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:767)
    	at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:245)
    	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:222)
    	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:265)
    	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
    	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
    	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
    	at util.HibernateUtil.getSessionFactory(HibernateUtil.java:20)
    	at org.metier.CatalogueMetierImpl.addProduit(CatalogueMetierImpl.java:14)
    	at org.metier.TestMetier.main(TestMetier.java:8)

  4. #24
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    Nom : hibernate.PNG
Affichages : 519
Taille : 14,6 Ko
    ce sont les fichiers donc tu en a besoin pour le faire. cela marche bien chez moi.

    Eric

  5. #25
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    145
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 145
    Points : 62
    Points
    62
    Par défaut
    Bonjour,

    Je ne comprends pas mais j'ai toujours la même erreur pourtant j'utilise exactement les mêmes jar!!

  6. #26
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    crees un nouveau projet.

  7. #27
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    145
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 145
    Points : 62
    Points
    62
    Par défaut
    J'ai pu corriger ce fameux problème.
    par contre j'ai un dernier petit problème, j'essaye de rentrer deux champs dans la table, mais il rentre la première, puis l'écrase avant de rentrer la seconde comme le montre ces logs.
    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
     
    avr. 06, 2016 12:14:15 AM org.hibernate.annotations.common.Version <clinit>
    INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
    avr. 06, 2016 12:14:15 AM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate Core {4.2.21.Final}
    avr. 06, 2016 12:14:15 AM org.hibernate.cfg.Environment <clinit>
    INFO: HHH000206: hibernate.properties not found
    avr. 06, 2016 12:14:15 AM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: HHH000021: Bytecode provider name : javassist
    avr. 06, 2016 12:14:15 AM org.hibernate.cfg.Configuration configure
    INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
    avr. 06, 2016 12:14:15 AM org.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
    avr. 06, 2016 12:14:15 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
    WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
    avr. 06, 2016 12:14:15 AM org.hibernate.cfg.Configuration doConfigure
    INFO: HHH000041: Configured SessionFactory: null
    avr. 06, 2016 12:14:16 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
    avr. 06, 2016 12:14:16 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000115: Hibernate connection pool size: 20
    avr. 06, 2016 12:14:16 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000006: Autocommit mode: false
    avr. 06, 2016 12:14:16 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/catalogue]
    avr. 06, 2016 12:14:16 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000046: Connection properties: {user=root, password=****}
    avr. 06, 2016 12:14:17 AM org.hibernate.dialect.Dialect <init>
    INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
    avr. 06, 2016 12:14:18 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
    INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
    avr. 06, 2016 12:14:18 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
    INFO: HHH000397: Using ASTQueryTranslatorFactory
    avr. 06, 2016 12:14:18 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: HHH000227: Running hbm2ddl schema export
    Hibernate: drop table if exists PRODUITS
    Hibernate: create table PRODUITS (ID_PRODUIT bigint not null auto_increment, DESIGNATION varchar(255), prix double precision not null, quantite integer not null, primary key (ID_PRODUIT))
    avr. 06, 2016 12:14:18 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: HHH000230: Schema export complete
    Hibernate: insert into PRODUITS (DESIGNATION, prix, quantite) values (?, ?, ?)
    avr. 06, 2016 12:14:19 AM org.hibernate.cfg.Configuration configure
    INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
    avr. 06, 2016 12:14:19 AM org.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
    avr. 06, 2016 12:14:19 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
    WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
    avr. 06, 2016 12:14:19 AM org.hibernate.cfg.Configuration doConfigure
    INFO: HHH000041: Configured SessionFactory: null
    avr. 06, 2016 12:14:19 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
    avr. 06, 2016 12:14:19 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000115: Hibernate connection pool size: 20
    avr. 06, 2016 12:14:19 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000006: Autocommit mode: false
    avr. 06, 2016 12:14:19 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/catalogue]
    avr. 06, 2016 12:14:19 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000046: Connection properties: {user=root, password=****}
    avr. 06, 2016 12:14:19 AM org.hibernate.dialect.Dialect <init>
    INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
    avr. 06, 2016 12:14:19 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
    INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
    avr. 06, 2016 12:14:19 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
    INFO: HHH000397: Using ASTQueryTranslatorFactory
    avr. 06, 2016 12:14:19 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: HHH000227: Running hbm2ddl schema export
    Hibernate: drop table if exists PRODUITS
    Hibernate: create table PRODUITS (ID_PRODUIT bigint not null auto_increment, DESIGNATION varchar(255), prix double precision not null, quantite integer not null, primary key (ID_PRODUIT))
    avr. 06, 2016 12:14:19 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: HHH000230: Schema export complete
    Hibernate: insert into PRODUITS (DESIGNATION, prix, quantite) values (?, ?, ?)

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

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Tu devrais éviter de créer les tables à chaque session factory, à moins que tu ne compte pas conserver tes données plus de quelques heures
    Tu devrais surtout éviter de créer une nouvelle sessionFactory à chaque fois. On vois bien dans tes logs que tu as créé deux session factory.

  9. #29
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    quelle est la valeur de ta propriété:
    car il fait ceci chaque fois:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    INFO: HHH000227: Running hbm2ddl schema export
    Hibernate: drop table if exists PRODUITS
    Hibernate: create table PRODUITS (ID_PRODUIT bigint not null auto_increment, DESIGNATION varchar(255), prix double precision not null, quantite integer not null, primary key (ID_PRODUIT))
    avr. 06, 2016 12:14:18 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: HHH000230: Schema export complete
    il devrais etre a update et non create.
    Eric

  10. #30
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    145
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 145
    Points : 62
    Points
    62
    Par défaut
    Rebonjour,
    J'ai de nouveau un petit problème (ou gros même d'ailleurs), lorsque je fais des requêtes vers ma base de donné. toutes les requêtes utilisant la méthode "createSQLQuery" ne marche pas, tandis que les autres méthodes marchent bien.
    Par exemple ces deux appels
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    List<Produit> prods = metier.getProduitParMc( "PS" );
            for ( Produit p1 : prods ) {
                System.out.println( p1.getDesignation() );
            }
     
            List<Produit> pr = metier.listProduit();
            for ( Produit p2 : pr ) {
                System.out.println( p2.getDesignation() );
            }
    dont voici le code
    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
     
     @Override
        public List<Produit> listProduit() {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            Query req = session.createSQLQuery( "select p from Produit p " );
            List<Produit> prods = req.list();
            session.getTransaction().commit();
     
            return prods;
        }
     
    @Override
        public List<Produit> getProduitParMc( String mc ) {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            Query req = session.createSQLQuery( "select p from Produit p where p.designation like :x" );
            req.setParameter( "x", "%" + mc + "%" );
            List<Produit> prods = req.list();
            session.getTransaction().commit();
            return prods;
        }
    me donnent les erreurs suivantes
    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
     
    Hibernate: select p from Produit p where p.designation like ?
    avr. 10, 2016 2:44:18 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    WARN: SQL Error: 1146, SQLState: 42S02
    avr. 10, 2016 2:44:18 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    ERROR: Table 'catalogue.Produit' doesn't exist
    Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    	at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
    	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
    	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)
    	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
    	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:88)
    	at org.hibernate.loader.Loader.getResultSet(Loader.java:2062)
    	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1859)
    	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
    	at org.hibernate.loader.Loader.doQuery(Loader.java:906)
    	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:348)
    	at org.hibernate.loader.Loader.doList(Loader.java:2550)
    	at org.hibernate.loader.Loader.doList(Loader.java:2536)
    	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2366)
    	at org.hibernate.loader.Loader.list(Loader.java:2361)
    	at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:340)
    	at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1788)
    	at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:232)
    	at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:157)
    	at org.metier.CatalogueMetierImpl.getProduitParMc(CatalogueMetierImpl.java:54)
    	at org.metier.TestMetier.main(TestMetier.java:20)
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'catalogue.Produit' doesn't exist
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    	at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    	at com.mysql.jdbc.Util.getInstance(Util.java:387)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
    	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
    	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551)
    	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
    	at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1962)
    	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
    	... 15 more

  11. #31
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    145
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 145
    Points : 62
    Points
    62
    Par défaut
    Pourtant cette requête marche bien
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    metier.addProduit( new Produit( "HP1234", 456.89, 4 ) );
            metier.addProduit( new Produit( "SAM78HV", 7896.00, 2 ) );
            metier.addProduit( new Produit( "PS4H12", 1200.00, 6 ) );
     
            Produit p = metier.getProduit( 1L );
            System.out.println( p.getDesignation() );
            System.out.println( p.getPrix() );
            p.setPrix( 111.11 );
            metier.updateProduit( p );
    code:
    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
     
    @Override
    public List<Produit> listProduit() {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            Query req = session.createSQLQuery( "select p from Produit p " );
            List<Produit> prods = req.list();
            session.getTransaction().commit();
     
            return prods;
     
        }
     
        @Override
        public void deleteProduit( Long idProd ) {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            Object p = session.get( Produit.class, idProd );
            if ( p == null )
                throw new RuntimeException( "Produit introuvable" );
            session.delete( p );
            session.getTransaction().commit();
        }
    log
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    Hibernate: drop table if exists PRODUITS
    Hibernate: create table PRODUITS (ID_PRODUIT bigint not null auto_increment, DESIGNATION varchar(255), prix double precision not null, quantite integer not null, primary key (ID_PRODUIT))
    avr. 10, 2016 2:44:17 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: HHH000230: Schema export complete
    Hibernate: insert into PRODUITS (DESIGNATION, prix, quantite) values (?, ?, ?)
    Hibernate: insert into PRODUITS (DESIGNATION, prix, quantite) values (?, ?, ?)
    Hibernate: insert into PRODUITS (DESIGNATION, prix, quantite) values (?, ?, ?)
    Hibernate: select produit0_.ID_PRODUIT as ID_PRODU1_0_0_, produit0_.DESIGNATION as DESIGNAT2_0_0_, produit0_.prix as prix3_0_0_, produit0_.quantite as quantite4_0_0_ from PRODUITS produit0_ where produit0_.ID_PRODUIT=?
    HP1234
    456.89
    Hibernate: update PRODUITS set DESIGNATION=?, prix=?, quantite=? where ID_PRODUIT=?

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

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    createSQLQuery, comme son nom l'indique, attends une requête SQL, pas une requête HQL. Donc des tables, pas des classes. Par défaut ça te retournera juste une List<Object[]> pas une List<Produit>.

    Pour une requête HQL comme tu le fais c'est createQuery.

  13. #33
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    145
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 145
    Points : 62
    Points
    62
    Par défaut
    Quelle erreur! merci

Discussions similaires

  1. Problème avec hibernate et MySQL!
    Par sofien dans le forum Outils
    Réponses: 5
    Dernier message: 27/08/2008, 09h06
  2. Les problémes avec Hibernate
    Par hichem_enis dans le forum Struts 1
    Réponses: 7
    Dernier message: 11/04/2008, 13h00
  3. Problème avec Hibernate
    Par ISID dans le forum Hibernate
    Réponses: 13
    Dernier message: 05/10/2007, 12h27
  4. Problème avec Hibernate synchronizer
    Par jason69 dans le forum Hibernate
    Réponses: 2
    Dernier message: 27/08/2007, 11h35
  5. [Hibernate] Problème avec Hibernate et Eclipse 3
    Par theseuby dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 30/03/2006, 21h31

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