Hibernate version: 3.0.5
Code between sessionFactory.openSession() and session.close():
Code:
public List find(String requete, Integer first, Integer qttMax) throws ObjectException{
System.err.println("hibernate.find("+requete+", "+first+", "+qttMax+")");
if (isOpen()){
List reponse = null;
Session session = null;
try{
session = getSess();
} catch (Throwable t){
String message = t.getMessage();
String exception = "Impossible de lancer la requete \n"+requete;
if (message!=null){
exception += "\n ("+message+")";
}
exception += "\n - "+t.getClass();
throw new ObjectException(exception);
}
if (session==null){
setOpen(false);
String exception = "Impossible de lancer la requete \n"+requete;
exception += "\n (session==null)";
throw new ObjectException(exception);
} else {
try {
Query query = session.createQuery(requete);
if (first!=null){
query.setFirstResult(first.intValue());
}
if (qttMax!=null){
query.setMaxResults(qttMax.intValue());
}
reponse = query.list();
} catch (Throwable e) {
String message = e.getMessage();
String exception = "Impossible de lancer la requete \n"+requete;
if (message!=null){
exception += "\n("+message+")";
}
exception += " - "+e.getClass();
e.printStackTrace();
throw new ObjectException(exception);
}
}
return reponse;
} else {
String exception = "Impossible de lancer la requete \n"+requete;
exception += "\n(Connexion fermée)";
throw new ObjectException(exception);
}
}
Full stack trace of any exception that occurs:
objets.objets.exceptions.ObjectException: Impossible de lancer la requete
select distinct year(dossier.dateEnvoi) from AvancementDossier dossier
(could not execute query) - class org.hibernate.exception.SQLGrammarException
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1596)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at utils.Hibernate.find(Hibernate.java:400)
at utils.Hibernate.find(Hibernate.java:345)
at test.TestHibernate.testCurrentConnection(TestHibernate.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.sql.SQLException: A syntax error has occurred.
at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:373)
at com.informix.jdbc.IfxSqli.a(IfxSqli.java:3208)
at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3518)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2353)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2269)
at com.informix.jdbc.IfxSqli.executePrepare(IfxSqli.java:1153)
at com.informix.jdbc.IfxPreparedStatement.e(IfxPreparedStatement.java:318)
at com.informix.jdbc.IfxPreparedStatement.a(IfxPreparedStatement.java:298)
at com.informix.jdbc.IfxPreparedStatement.<init>(IfxPreparedStatement.java(Compiled Code))
at com.informix.jdbc.IfxSqliConnect.h(IfxSqliConnect.java:5909)
at com.informix.jdbc.IfxSqliConnect.prepareStatement(IfxSqliConnect.java:1991)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:396)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:334)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
... 24 more
Name and version of the database you are using: IBM Informix Dynamic Server Version 9.40.TC7
le SQL que je donne à Hibernate :
select distinct year(dateEnvoi) from AvancementDossier
The generated SQL (show_sql=true):
select distinct extract(year from avancement0_.DATEENVOI) as col_0_0_ from teleservices.AVANCEMENTDOSSIER avancement0_
Ce que répond Informix quand je lui envoie la requête qu'a généré Hibernate : [b]
Database selected. 201: A syntax error has occurred. Error in line 1 Near character position 30 Database closed.
[b]Les jars pour informix utilisés : ifxjdbc.jar et ifxsqlj.jar
hibernate.properties :
hibernate.dialect org.hibernate.dialect.InformixDialect
hibernate.connection.driver_class com.informix.jdbc.IfxDriver
hibernate.connection.autocommit true
hibernate.connection.isolation 2
hibernate.default_schema teleservices
Je pense que je dois avoir un problème de version. La requête que j'envoie, non modifiée, dans Informix fonctionne. Par contre, celle que génère Hibernate n'est pas reconnue. Quelqu'un a t il une idée ? Merci