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 :

Requete qui marche une fois mais pas deux


Sujet :

Hibernate Java

  1. #1
    Membre du Club
    Inscrit en
    Mars 2002
    Messages
    82
    Détails du profil
    Informations forums :
    Inscription : Mars 2002
    Messages : 82
    Points : 55
    Points
    55
    Par défaut Requete qui marche une fois mais pas deux
    Bonjour,

    Voila mon 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
     
    	public Integer getNumberOperationByCriteria(Integer status, Integer category, CalendarDate accountingDate, Set profitCenterSet) throws ApisTechnicalException {
     
    		String date = accountingDate.toString(ApisCoreConstants.databaseDatePattern);
    		Integer result = null;
     
    		try {
    				Query query = getPersistenceManager().getNamedQuery(Prrt.QUERY_GET_NUMBER_OPERATION_BY_CRITERIA);
    				query.setString("status", String.valueOf(status));
    				query.setString("category", String.valueOf(category));
    				query.setInteger("date", Integer.valueOf(date).intValue());
     
    				query.setString("profitCenter",  buildString(profitCenterSet));
    				result = (Integer) query.uniqueResult();
    				getPersistenceManager().flush();
    		} catch (HibernateException e) {
    			e.printStackTrace();
    			throw new ApisTechnicalException("TECHNICAL_EXCEPTION", null, e);
    		}
     
    		return result;
    	}
    voila ma requete nommé dans mon fichier hbm:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    	<query name="PRRT.get_number_operation_by_criteria">
    		<![CDATA[
    			select count(prrt)
    			from Prrt prrt
    			where prrt.prrtStus like :status
    			and prrt.prrtCatgoper like :category
    			and prrt.prrtDateacnt = :date
    			and prrt.prrtRcen IN (:profitCenter)
    		]]>
    	</query>
    Cette fonction est appelé par une boucle, la premiere fois où je l'appelle tout se passe bien mais à la deuxieme j'ai le message suivant:
    23/01/07 11:24:55:024 CET] 6140614 JDBCException W org.hibernate.util.JDBCExceptionReporter SQL Error: 1722, SQLState: 42000
    [23/01/07 11:24:55:087 CET] 6140614 JDBCException E org.hibernate.util.JDBCExceptionReporter ORA-01722: invalid number

    org.hibernate.exception.GenericJDBCException: could not execute query
    at java.lang.Throwable.<init>(Throwable.java)
    at java.lang.Throwable.<init>(Throwable.java)
    at org.hibernate.exception.NestableRuntimeException.<init>(NestableRuntimeException.java:124)
    at org.hibernate.JDBCException.<init>(JDBCException.java:20)
    at org.hibernate.JDBCException.<init>(JDBCException.java:25)
    at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
    at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
    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 org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:603)
    at ............
    Caused by: java.sql.SQLException: ORA-01722: invalid number

    J'ai pris la requete sql généré par hibernate:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    select count(prrt0_.PRRT_OPRF) as col_0_0_ from PRRT prrt0_ where (prrt0_.PRRT_STUS like ?) and (prrt0_.PRRT_CATGOPER like ?) and prrt0_.PRRT_DATEACNT=? and (prrt0_.PRRT_RCEN in (?))
    En debug j'ai recupéré les valeurs de chaque parametre et j'ai pu execute ma requete sql dans toad sans probleme.

    Je comprends vraiment pas d'où viens le probleme.

  2. #2
    Membre expérimenté Avatar de maxf1
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 229
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 229
    Points : 1 371
    Points
    1 371
    Par défaut
    Question:

    getPersistenceManager() => methode qui fait quoi? (tu peux mettre le code)

  3. #3
    Membre du Club
    Inscrit en
    Mars 2002
    Messages
    82
    Détails du profil
    Informations forums :
    Inscription : Mars 2002
    Messages : 82
    Points : 55
    Points
    55
    Par défaut
    Elle renvoie la hibernateSession courante, qui a été ouverte quelques methodes plus haut.

    Voici la fonction buildString:

    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
    	private String stringProfitCenter = null;
     
    	private String buildString(Set profitCenterSet){
    		if(stringProfitCenter==null){
    			StringBuffer buffer = new StringBuffer();
    			Iterator it = profitCenterSet.iterator();
    			if(it.hasNext()){
    				ResponsabilityCenter responsabilityCenter = (ResponsabilityCenter) it.next();
    				buffer.append("'");
    				buffer.append(responsabilityCenter.getIsbaCode().intValue());
    				buffer.append("'");
    				for (; it.hasNext();) {
    					responsabilityCenter = (ResponsabilityCenter) it.next();
    					buffer.append(",");
    					buffer.append("'");
    					buffer.append(responsabilityCenter.getCode().intValue());
    					buffer.append("'");
    				}
    			}
    			stringProfitCenter = buffer.toString();
    		}
    		return stringProfitCenter;
    	}

  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 141
    Points
    4 141
    Par défaut
    Je n'ai pas de réponse à ton problème, mais pour remplir les
    paramètres d'un in(....), tu peux utiliser la méthode:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    query.setParameterList(...);

  5. #5
    Membre du Club
    Inscrit en
    Mars 2002
    Messages
    82
    Détails du profil
    Informations forums :
    Inscription : Mars 2002
    Messages : 82
    Points : 55
    Points
    55
    Par défaut
    Merci beaucoup fr1man, ta solution corrige le probleme. Je ne sais pas pourquoi mais le principale c'est que ce soit bon. Encore une fois merci.

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

Discussions similaires

  1. getimagesize une fois mais pas deux.
    Par Jasou dans le forum Langage
    Réponses: 3
    Dernier message: 05/08/2010, 15h40
  2. Une fonction qui marche 8 fois mais pas 9
    Par Swarley dans le forum Prolog
    Réponses: 1
    Dernier message: 04/12/2008, 10h21
  3. Pb sur une fct qui marche sous mozilla mais pas ie
    Par chpog dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 21/09/2005, 11h26
  4. Réponses: 2
    Dernier message: 04/06/2004, 11h11
  5. Pb : malloc qui marche une fois sur deux .... ?
    Par guillaume_pfr dans le forum C
    Réponses: 14
    Dernier message: 21/07/2003, 09h52

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