These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: Suppression de plusieurs instance
PostPosted: Tue Mar 06, 2007 8:23 am 
Newbie

Joined: Tue Nov 21, 2006 5:47 am
Posts: 12
Bonjour à tous,
je cherche la syntaxe en HQL pour la suppresion de plusiers instance.
j'ai essayé le code suivant mais il marche pas:

String hqlDelete = "delete Project p where p.id in lstId";
// lstId est un tableau de id
int deletedEntities = session.createQuery( hqlDelete )
.setParameter("lstId", _projectId)
.executeUpdate();

ou bien utiliser
session.createCriteria(Project.class).add(Restrictions.in("id", _projectId));


Merci de votre aide.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 8:49 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Ca veut dire quoi ça marche pas ? Quel est le sql généré ? que se passe t'il ? Quel est le retour d'hibernate ?

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 11:27 am 
Newbie

Joined: Tue Nov 21, 2006 5:47 am
Posts: 12
bonjour,
l'exception retournée est :
org.hibernate.HibernateException: could not locate named parameter [lstId]

ou lstId est un tableau d'id que je veux supprimé.

Merci


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 11:50 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Il faut mettre :listId dans la requète comme expliqué dans la doc pour les named parameters

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 12:11 pm 
Newbie

Joined: Tue Nov 21, 2006 5:47 am
Posts: 12
c'est ce jke j'ai fait :

String hqlDelete = "delete Project p where p.id in lstId";
// lstId est un tableau de id
int deletedEntities = session.createQuery( hqlDelete )
.setParameter("lstId", _projectId)
.executeUpdate();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 12:16 pm 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Code:
String hqlDelete = "delete Project p where p.id in :lstId";
// lstId est un tableau de id
int deletedEntities = session.createQuery( hqlDelete )
.setParameter("lstId", _projectId)
.executeUpdate();

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 12:35 pm 
Newbie

Joined: Tue Nov 21, 2006 5:47 am
Posts: 12
Merci pour votre réactivité.
Maintenant je recois l'exception suivante:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: : near line 1, column 60 [delete fr.sgf.unittestportal.model.Project p where p.id in :lstId]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:244)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:155)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
at fr.sgf.unittestportal.dao.impl.ProjectDAO.delete(ProjectDAO.java:129)
at fr.sgf.unittestportal.dao.impl.TestProjectAdminDAO.testDeleteListIdProject(TestProjectAdminDAO.java:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at fr.sgf.tools.hibernate.AHibernateTestCase.runTest(AHibernateTestCase.java:140)
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.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: line 1:60: unexpected token: :
at org.hibernate.hql.antlr.HqlBaseParser.compoundExpr(HqlBaseParser.java:3064)
at org.hibernate.hql.antlr.HqlBaseParser.inList(HqlBaseParser.java:2858)
at org.hibernate.hql.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2720)
at org.hibernate.hql.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2449)
at org.hibernate.hql.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2413)
at org.hibernate.hql.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2331)
at org.hibernate.hql.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2296)
at org.hibernate.hql.antlr.HqlBaseParser.expression(HqlBaseParser.java:2082)
at org.hibernate.hql.antlr.HqlBaseParser.logicalExpression(HqlBaseParser.java:1858)
at org.hibernate.hql.antlr.HqlBaseParser.whereClause(HqlBaseParser.java:454)
at org.hibernate.hql.antlr.HqlBaseParser.deleteStatement(HqlBaseParser.java:266)
at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:148)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:238)
... 29 more


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 12:44 pm 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Peut être plutôt
Code:
delete Project p where p.id in (:lstId)

C'est ce que j'utilise dans mes select

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 1:09 pm 
Newbie

Joined: Tue Nov 21, 2006 5:47 am
Posts: 12
ca marche merci infiniment


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 1:12 pm 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
De rien, tu peux aussi l'exprimer en credit :-)

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.