Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » @NamedQuery "DELETE FROM"
@NamedQuery "DELETE FROM" [message #478235] Thu, 06 August 2009 09:00 Go to next message
Enrico is currently offline EnricoFriend
Messages: 82
Registered: July 2009
Member
Hi all,

I have a @NamedQuery that should delete fomr DB rows basing on my
conditions.
When I try to run the query, the following error occour:

JAVA.LANG.ILLEGALSTATEEXCEPTION: EXCEPTION DESCRIPTION: NO TRANSACTION
IS CURRENTLY ACTIVE

Note:
1. i have no problem with the "SELECT" @NamedQuery
2. if I try to run the SQL of the created @NamedQuery from outside, the
rows are correctly removed.

What can be the problem?I need to set somethink on persistece.xml
configuration?There is additional task to do for delete query?

BR,
Enrico
Re: @NamedQuery "DELETE FROM" [message #478817 is a reply to message #478235] Fri, 07 August 2009 06:38 Go to previous message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
In which Environment are you running EL. If you are in a Java ee and run
you session beans container managed, the the EE container should handle
transactions for you. If you are in a JavaSE environment, you need to
deal with transactions yourself. This is why EL is complaining that
there is no transaction active. The select query is only reading, and
reading access does not require a transaction.

Try the following:

You need to encapsulate all your writing queries with a transaction.

em.getTransaction().begin();
em.createNamedQuery("YourDeletingNamedQuery").executeUpdate();
em.getTransaction().commit();

HTH

Tom

P.S. If you are running container managed transactions on an
Applicationserver (e.g. JBoss), i think there is a configuration
problem, because the container should handle the transactions for you.

Enrico schrieb:
> Hi all,
>
> I have a @NamedQuery that should delete fomr DB rows basing on my
> conditions.
> When I try to run the query, the following error occour:
>
> JAVA.LANG.ILLEGALSTATEEXCEPTION: EXCEPTION DESCRIPTION: NO TRANSACTION
> IS CURRENTLY ACTIVE
>
> Note:
> 1. i have no problem with the "SELECT" @NamedQuery
> 2. if I try to run the SQL of the created @NamedQuery from outside, the
> rows are correctly removed.
>
> What can be the problem?I need to set somethink on persistece.xml
> configuration?There is additional task to do for delete query?
>
> BR,
> Enrico
Previous Topic:EclipseLink Expressions - is there a better way to design the DAO?
Next Topic:Testing with Fragment-Plugins
Goto Forum:
  


Current Time: Thu Nov 27 05:59:22 GMT 2014

Powered by FUDForum. Page generated in 0.02590 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software