-->
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.  [ 9 posts ] 
Author Message
 Post subject: problems with delete(query)
PostPosted: Mon Dec 08, 2003 9:36 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 4:32 pm
Posts: 36
Location: S
What


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 9:39 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You are not binding an argument to your delete statement parameter. Your code is wrong, just look at it again.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: whats wrong ?
PostPosted: Mon Dec 08, 2003 9:44 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 4:32 pm
Posts: 36
Location: S
but I am using setParameter. Isn


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 9:46 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You set the parameter, and then don't execute the query. The only thing you do is passing the query string to the delete().

Check the API documentation for delete(), you can used positional parameters (no Query).

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 9:58 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 4:32 pm
Posts: 36
Location: S
Sorry. I


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 10:05 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Please read the documentation and API Javadoc for Session.delete():

delete(String query)
Delete all objects returned by the query.

delete(String query, Object[] values, Type[] types)
Delete all objects returned by the query.

delete(String query, Object value, Type type)
Delete all objects returned by the query.

You use a query string like "from myClass foo where foo.someAttribute = ?" and then bind a value to that parameter. This is the same mechanism as for Session.find(), which is well documented everywhere.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 10:11 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 4:32 pm
Posts: 36
Location: S
sorry,

then my code is correct, isn


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 10:18 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, its not. Look, you just say:

Code:
int regDel = session.delete(query.getQueryString());


which is like executing:

Code:
int regDel = session.delete("from TbPerson as tbPerson where tbPerson.comp_id.cdPerson = :cdPessoa");


The argument you bind to the Query in the lines before that are not executed, because you are not executing the Query object, but only the string!

Try to understand the following code:

Code:
String cdPessoa = "aValue";

String queryString = "from TbPerson as tbPerson where tbPerson.comp_id.cdPerson = ?";

int regDel = session.delete(queryString, new Object[]{cdPessoa}, new Type[]{Hibernate.STRING});

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 10:30 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 4:32 pm
Posts: 36
Location: S
Ok ..

It


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.