openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "C N Davies" <...@cndavies.com>
Subject RE: Bug in Delete from query ?
Date Mon, 14 Sep 2009 16:37:47 GMT
I hit the same thing myself some time back, it's a bit of an anomaly because
in SQL you can use "delete from table" and if you don't specify a WHERE
clause it will delete everything from the table.

Just my 2c

Chris


-----Original Message-----
From: David Beer [mailto:david.m.beer@googlemail.com] 
Sent: Monday, 14 September 2009 11:44 PM
To: users@openjpa.apache.org
Subject: Re: Bug in Delete from query ?

On Mon, 14 Sep 2009 09:19:43 +0200
Fabien Charlet <fabien.charlet@gmail.com> wrote:

> Hello !
> 
> I'm quite new to JPA and OpenJPA.
> I have developped a DAL using OpenJPA and HSQLDB for tests.
> 
> My problem is when I launch a "Delete from" query, HSQLDB complains
> about a malformed SQL syntax.
> 
> Here is my query :
> 
> final Query q = entityManager.get().createQuery("DELETE FROM Log");
> q.executeUpdate();
> 
> Where Log is an entity configured.
> But OpenJPA generates the query :
> 
> DELETE FROM LOG t0
> 
> And HsqlDB replies :
> 
> Caused by: org.hsqldb.HsqlException: unexpected token: T0
> 	at org.hsqldb.Error.error(Error.java:76)
> 	at org.hsqldb.ParserBase.unexpectedToken(ParserBase.java:749)
> 	at
> org.hsqldb.ParserCommand.compileStatement(ParserCommand.java:66) at
> org.hsqldb.Session.compileStatement(Session.java:808) at
> org.hsqldb.StatementManager.compile(StatementManager.java:418) at
> org.hsqldb.Session.execute(Session.java:882) at
>
org.hsqldb.jdbc.JDBCPreparedStatement.<init>(JDBCPreparedStatement.java:3631
)
> 
> I quickly looked at HsqlDB specs
> (http://hsqldb.org/web/hsqlDocsFrame.html), where I find that the
> query should be
> 
> DELETE FROM LOG
> 
> without the ending T0.
> 
> Is someone know this issue ?
> 
> I am using OpenJPA 1.2.1 and HsqlDB hsqldb-1.9.0-rc4
> 
> Thanks for help.
> 

Hi What it is it you are trying to delete an item from the table or the
table. As in general you have not specified what it has to delete.

The documentation actually says "DELETE FROM table [WHERE
Expression];" which will delete rows. You need to tell it what to
delete in the LOG table. 

-- 
Best Regards

David Beer

http://www.thebeerfamily.com


Mime
View raw message