Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / March 2007

Tip: Looking for answers? Try searching our database.

Hibernate305: delete query fails with "must begin with SELECT or FROM"

Thread view: 
david.karr - 27 Mar 2007 00:01 GMT
(I posted this first to c.l.j.p, but I realized it's more appropriate
here.)

I'm following the Hibernate 3.0.5 docs to build a query to delete rows
from a table.  My code looks something like this:

-----------------
String  hql = "delete ReqField " +
                     "where fieldName = :fieldName and value
= :value";
Query   query   =
      sessionFactory.getCurrentSession().createQuery(hql);
query.setString("fieldName", fieldName);
query.setString("value", value);

int deletedRows = query.executeUpdate();
-----------------

This fails with:

org.hibernate.QueryException: query must begin with SELECT or FROM:
delete [delete ReqField where fieldName = :fieldName and value
= :value]

What is wrong with my query?

I also tried changing "delete ReqField" to "delete from ReqField", but
that still gets the same error message (with "delete from" in the
message).
joeNOSPAM@BEA.com - 27 Mar 2007 01:31 GMT
> (I posted this first to c.l.j.p, but I realized it's more appropriate
> here.)
[quoted text clipped - 25 lines]
> that still gets the same error message (with "delete from" in the
> message).

I guess you should not use a query object for an update, insert or
delete,
just queries.
david.karr - 27 Mar 2007 03:07 GMT
On Mar 26, 5:31 pm, "joeNOS...@BEA.com" <joe.weinst...@gmail.com>
wrote:

> > (I posted this first to c.l.j.p, but I realized it's more appropriate
> > here.)
[quoted text clipped - 29 lines]
> delete,
> just queries.

So how can you delete rows from a query?  I tried the "deprecated"
form of "Session.delete(querystr)", but that doesn't work either (I
can't remember what failed there).

I guess I'll have to make sure the session is not in auto-commit and
iterate through all the objects manually, calling "delete()" on them.
I hope that will work.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.