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 en rajoutant sql natif


Sujet :

Hibernate Java

  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    108
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 108
    Par défaut erreur en rajoutant sql natif
    Bonsoir,
    j'ai un message d'erreur dès que je veux rajouter la requete sql native :
    Query sqlQuery = session.createSQLQuery("SELECT pkg_1.fn_getexport (" + resultat[0]+ " ," + resultat[1] + ",4,4) from dual", "Export", null);
    out.write( (String) sqlQuery.list().get(0));


    voici le code source Test.java:
    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
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import net.sf.hibernate.*;
    import com.test.hibernate.*;
    
    public class Test 
    {
    public static void main(String[] args)
    	throws HibernateException, IOException 
    	{	
    	// Create file out
        FileWriter fstream = new FileWriter("out.xml");
        BufferedWriter out = new BufferedWriter(fstream);   
        
        // connexion base de donnee
    	Session session = HibernateUtil.currentSession();
    	
    	
    	// Query
        Query query = session.createQuery
        (
        "SELECT ve.IdSigle, ve.RefClient " +
        "FROM Ventesentete ve,Venteslignes vl "
        );
        
    
        List list = query.list(); 
    	Iterator it = list.iterator();
    	out.write("<dossiers>" );
    	 while(it.hasNext())
    	 {
    	  Object []  resultat = (Object [])it.next();	
    	  
    	  Query sqlQuery = session.createSQLQuery("SELECT  pkg_1.fn_getexport (" + resultat[0]+ " ," + resultat[1] + ",4,4) from dual", "Export", null);
    	  out.write( (String) sqlQuery.list().get(0));
    
    	  out.write("<idsigle>" );
    	  out.write(String.valueOf(resultat[0]));
    	  out.write("</idsigle><refclient>" );
    	  out.write((String) resultat[1]);
    	  out.write("</refclient>");
    	  out.write("\n");
    	 }
    	 out.write("</dossiers>" );
    	 
    	 //Close the output stream and connexion
    	 out.close();
    	 HibernateUtil.closeSession();
        }
    }
    erreur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    Exception in thread "main" java.lang.NullPointerException
    	at net.sf.hibernate.impl.SessionImpl.getSQLLoadable(SessionImpl.java:3819)
    	at net.sf.hibernate.impl.SessionImpl.findBySQL(SessionImpl.java:3796)
    	at net.sf.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:52)
    	at Test.main(Test.java:41)
    merci de votre aide

  2. #2
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Il y a une erreur dans ta création du SQLQuery.
    La méthode createSQLQuery n'accepte qu'un seul argument String, là, tu lui en passes 3
    1) "SELECT pkg_1.fn_getexport (" + resultat[0]+ " ," + resultat[1] + ",4,4) from dual"
    2) "Export"
    3) null
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    108
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 108
    Par défaut
    Non justement, j'ai déja essayé avec un parametre:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Query net.sf.hibernate.Session.createSQLQuery(String arg0, String arg1, Class arg2)
    Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be found.
    pour info j'utilise Hibernate 2

  4. #4
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    108
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 108
    Par défaut
    je suis passé sur Hibernate 3. maintenant j'ai cette erreur:

    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
    Exception in thread "main" java.lang.ExceptionInInitializerError
    	at Test.main(Test.java:17)
    Caused by: java.lang.RuntimeException: Problème de configuration Hibernate : could not instantiate id generator
    	at com.test.hibernate.hibernateUtil.<clinit>(hibernateUtil.java:22)
    	... 1 more
    Caused by: org.hibernate.MappingException: could not instantiate id generator
    	at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:98)
    	at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:152)
    	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:192)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
    	at com.test.hibernate.hibernateUtil.<clinit>(hibernateUtil.java:18)
    	... 1 more
    Caused by: org.hibernate.MappingException: could not interpret id generator strategy: vm
    	at org.hibernate.id.IdentifierGeneratorFactory.getIdentifierGeneratorClass(IdentifierGeneratorFactory.java:109)
    	at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:92)
    	... 5 more

    voici la source: ubirnateUtil.java:

    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
    package com.test.hibernate;
    import org.hibernate.*;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
     
    public class hibernateUtil {
     
     
    private static final SessionFactory sessionFactory;
     
    public static final ThreadLocal session = new ThreadLocal();
     
    static {
     
    try {
     
    sessionFactory = new Configuration().configure().buildSessionFactory();
     
    } catch (HibernateException ex) {
     
    throw new RuntimeException("Problème de configuration Hibernate : " + ex.getMessage(), ex);
    }
    }
     
    public static Session getSession() throws HibernateException {
     
    Session s = (Session) session.get();
    if (s == null) {
    s = sessionFactory.openSession();
    session.set(s);
    }
     
    return s;
    }
     
    public static void closeSession() throws HibernateException {
     
    Session s = (Session) session.get();
    session.set(null);
    if (s != null)
    s.close();
     
    }
     
    }

  5. #5
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Là c'est un problème de stratégie de génération de la clé primaire.
    Il faudrait montrer le fichier hbm et préciser la base de données cible.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  6. #6
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    108
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 108
    Par défaut
    effectivement le hbm.xml je l'ai généré avec Hibernatesynchro qui genere du code pour le hibernate 2, il manqué la balise <generator class="native"/>
    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
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    	"-//Hibernate/Hibernate Mapping DTD//EN"
    	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
     
    <hibernate-mapping package="com.test.hibernate">
    	<class name="Ventesentete" table="VENTESENTETE">
    		<id
    			column="ID_SIGLNUM"
    			name="IdSiglnum"
    			type="integer"
    		>
    			<generator class="native"/>
     
    		</id>

    par contre j'ai une erreur:

    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
    Exception in thread "main" java.lang.NoSuchMethodError: net.sf.cglib.proxy.Enhancer.setInterceptDuringConstruction(Z)V
    	at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:126)
    	at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
    	at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
    	at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
    	at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
    	at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
    	at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:295)
    	at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
    	at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
    	at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
    	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
    	at com.test.hibernate.hibernateUtil.<clinit>(hibernateUtil.java:18)
    	at Test.main(Test.java:17)

  7. #7
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Ça va être difficile de t'aider si tu ne présentes que des fragments...

    Quelle base de données utilises-tu ?
    Il serait préférable d'utiliser un générateur "sequence" plutôt que "native" si c'est Oracle ou utiliser "identity" si c'est MySQL etc...

    L'erreur que tu montres pourrait venir d'une dépendance d'Hibernate... (un jar)
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  8. #8
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    108
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 108
    Par défaut
    j'utilise Oracle, voici mon hbm:
    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
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    	"-//Hibernate/Hibernate Mapping DTD//EN"
    	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
     
    <hibernate-mapping package="com.test.hibernate">
    	<class name="Ventesentete" table="VENTESENTETE">
    		<id
    			column="ID_SIGLNUM"
    			name="IdSiglnum"
    			type="integer"
    		>
    			<generator class="sequence"/>
     
    		</id>
    		<property
    			column="VENT_FLASHCOUNT"
    			length="20"
    			name="VentFlashcount"
    			not-null="false"
    			type="integer"
    		 />
    		<property
    			column="EMAIL_FACT"
    			length="80"
    			name="EmailFact"
    			not-null="false"
    			type="string"
    		 />
     
    	</class>
    </hibernate-mapping>
    erreur:

    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
    Exception in thread "main" java.lang.NoSuchMethodError: net.sf.cglib.proxy.Enhancer.setInterceptDuringConstruction(Z)V
    	at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:126)
    	at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
    	at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
    	at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
    	at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
    	at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
    	at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:295)
    	at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
    	at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
    	at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
    	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
    	at com.test.hibernate.hibernateUtil.<clinit>(hibernateUtil.java:18)
    	at Test.main(Test.java:17)

  9. #9
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 276
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 276
    Par défaut
    Tu n'as pas la bonne version de cglib.
    Il te faut la bonne version des jars pour la version 3 d'Hibernate, maintenant que tu en as changé.

  10. #10
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    108
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 108
    Par défaut
    merci bcp pour de ton aide c'été bien cela, parcontre maintenant j'ai une erreur qui n'est pas lié à Hibernate, je pense c'es au niveau de type de données, tu as une idée? merci de ton aide
    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
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import org.hibernate.*;
    import com.test.hibernate.*;
     
    public class Test 
    {
    public static void main(String[] args)
    	throws HibernateException, IOException 
    	{	
    	// Create file out
        FileWriter fstream = new FileWriter("out.xml");
        BufferedWriter out = new BufferedWriter(fstream);   
     
        // connexion base de donnee
    	Session session = (Session) hibernateUtil.getSession();
     
     
    	// Query
        Query query = session.createQuery
        (
        "SELECT ve.IdSigle, ve.RefClient " +
        "FROM Ventesentete ve,Venteslignes vl " +
        "WHERE ve.IdSiglnum= vl.IdSiglnum " 
        );
     
     
        List list = query.list(); 
    	Iterator it = list.iterator();
    	out.write("<dossiers>" );
    	 while(it.hasNext())
    	 {
    	  Object []  resultat = (Object [])it.next();	  
    	  Query sqlQuery = session.createSQLQuery("SELECT pkg.fnctionexport (" + resultat[0]+ " ," + resultat[1] + ",445099,445107 ) from dual");
    	  out.write( (String) sqlQuery.list().get(0));
     
    	  out.write("<idsigle>" );
    	  out.write(String.valueOf(resultat[0]));
    	  out.write("</idsigle><refclient>" );
    	  out.write((String) resultat[1]);
    	  out.write("</refclient>");
    	  out.write("\n");
    	 }
    	 out.write("</dossiers>" );
     
    	 //Close the output stream and connexion
    	 out.close();
    	 hibernateUtil.closeSession();
        }
    }
    erreur:
    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
    Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
    	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    	at org.hibernate.loader.Loader.doList(Loader.java:2148)
    	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
    	at org.hibernate.loader.Loader.list(Loader.java:2024)
    	at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:111)
    	at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1655)
    	at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
    	at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164)
    	at Test.main(Test.java:40)
    Caused by: java.sql.SQLException: ORA-00904: "EX0000517" : identificateur non valide
     
    	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
    	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:330)
    	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:287)
    	at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:742)
    	at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:212)
    	at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:795)
    	at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1030)
    	at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:835)
    	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1123)
    	at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3284)
    	at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3328)
    	at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
    	at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
    	at org.hibernate.loader.Loader.doQuery(Loader.java:662)
    	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
    	at org.hibernate.loader.Loader.doList(Loader.java:2145)
    	... 7 more

  11. #11
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    108
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 108
    Par défaut
    c'st réglé! merci à tous, en fait c'été un probleme de conversion integer -> string

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

Discussions similaires

  1. Erreur dans conditions SQL*Loader
    Par mike_made dans le forum SQL
    Réponses: 5
    Dernier message: 05/05/2006, 16h19
  2. erreur dans requete Sql
    Par flOZ dans le forum Requêtes
    Réponses: 2
    Dernier message: 02/05/2006, 02h49
  3. [erreur MFC et SQL]
    Par torNAdE dans le forum MFC
    Réponses: 4
    Dernier message: 26/04/2006, 14h25
  4. Erreur d'installation SQL SERVEUR
    Par JPCOCU dans le forum MS SQL Server
    Réponses: 5
    Dernier message: 11/01/2006, 17h08
  5. Recuperer les erreurs des requetes sql en asp
    Par emile13 dans le forum ASP
    Réponses: 3
    Dernier message: 01/04/2004, 13h49

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